Update go-ini dependency and remove semicolon hack in translations (#2913)

This commit is contained in:
Lauris BH 2017-11-15 05:34:42 +02:00 committed by Lunny Xiao
parent bd23e36bec
commit a6f337046f
17 changed files with 584 additions and 429 deletions

12
vendor/github.com/Unknwon/i18n/Makefile generated vendored Normal file
View file

@ -0,0 +1,12 @@
.PHONY: build test bench vet
build: vet bench
test:
go test -v -cover
bench:
go test -v -cover -test.bench=. -test.benchmem
vet:
go vet

View file

@ -1,4 +1,4 @@
i18n
i18n [![GoDoc](https://godoc.org/github.com/Unknwon/i18n?status.svg)](https://godoc.org/github.com/Unknwon/i18n) [![Sourcegraph](https://sourcegraph.com/github.com/Unknwon/i18n/-/badge.svg)](https://sourcegraph.com/github.com/Unknwon/i18n?badge)
====
Package i18n is for app Internationalization and Localization.
@ -131,4 +131,6 @@ This command can operate 1 or more files in one command.
## More information
If the key does not exist, then i18n will return the key string to caller. For instance, when key name is `hi` and it does not exist in locale file, simply return `hi` as output.
- The first locale you load to the module is considered as **default locale**.
- When matching non-default locale and didn't find the string, i18n will have a second try on default locale.
- If i18n still cannot find string in the default locale, raw string will be returned. For instance, when the string is `hi` and it does not exist in locale file, simply return `hi` as output.

View file

@ -156,7 +156,10 @@ func GetDescriptionByLang(lang string) string {
}
func SetMessageWithDesc(lang, langDesc string, localeFile interface{}, otherLocaleFiles ...interface{}) error {
message, err := ini.Load(localeFile, otherLocaleFiles...)
message, err := ini.LoadSources(ini.LoadOptions{
IgnoreInlineComment: true,
UnescapeValueCommentSymbols: true,
}, localeFile, otherLocaleFiles...)
if err == nil {
message.BlockMode = false
lc := new(locale)
@ -194,10 +197,11 @@ func (l Locale) Index() int {
// Tr translates content to target language.
func Tr(lang, format string, args ...interface{}) string {
var section string
parts := strings.SplitN(format, ".", 2)
if len(parts) == 2 {
section = parts[0]
format = parts[1]
idx := strings.IndexByte(format, '.')
if idx > 0 {
section = format[:idx]
format = format[idx+1:]
}
value, ok := locales.Get(lang, section, format)
@ -208,15 +212,17 @@ func Tr(lang, format string, args ...interface{}) string {
if len(args) > 0 {
params := make([]interface{}, 0, len(args))
for _, arg := range args {
if arg != nil {
val := reflect.ValueOf(arg)
if val.Kind() == reflect.Slice {
for i := 0; i < val.Len(); i++ {
params = append(params, val.Index(i).Interface())
}
} else {
params = append(params, arg)
if arg == nil {
continue
}
val := reflect.ValueOf(arg)
if val.Kind() == reflect.Slice {
for i := 0; i < val.Len(); i++ {
params = append(params, val.Index(i).Interface())
}
} else {
params = append(params, arg)
}
}
return fmt.Sprintf(format, params...)