mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 02:17:05 +00:00
Former-commit-id: 12b75f1e54ebf3d7f78a09b8d5594859a344422d
This commit is contained in:
14
i18n/i18n.go
14
i18n/i18n.go
@@ -248,6 +248,13 @@ func parsePath(m *Matcher, path string) int {
|
||||
return -1
|
||||
}
|
||||
|
||||
func reverseStrings(s []string) []string {
|
||||
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func parseLanguage(path string) (language.Tag, bool) {
|
||||
if idx := strings.LastIndexByte(path, '.'); idx > 0 {
|
||||
path = path[0:idx]
|
||||
@@ -259,6 +266,8 @@ func parseLanguage(path string) (language.Tag, bool) {
|
||||
return r == '_' || r == os.PathSeparator || r == '/' || r == '.'
|
||||
})
|
||||
|
||||
names = reverseStrings(names) // see https://github.com/kataras/i18n/issues/1
|
||||
|
||||
for _, s := range names {
|
||||
t, err := language.Parse(s)
|
||||
if err != nil {
|
||||
@@ -303,7 +312,7 @@ func (i *I18n) Tr(lang, format string, args ...interface{}) string {
|
||||
return msg
|
||||
}
|
||||
|
||||
return fmt.Sprintf(format, args...)
|
||||
return ""
|
||||
}
|
||||
|
||||
const acceptLanguageHeaderKey = "Accept-Language"
|
||||
@@ -372,6 +381,7 @@ func (i *I18n) GetLocale(ctx context.Context) context.Locale {
|
||||
}
|
||||
|
||||
// GetMessage returns the localized text message for this "r" request based on the key "format".
|
||||
// It returns an empty string if locale or format not found.
|
||||
func (i *I18n) GetMessage(ctx context.Context, format string, args ...interface{}) string {
|
||||
loc := i.GetLocale(ctx)
|
||||
if loc != nil {
|
||||
@@ -382,7 +392,7 @@ func (i *I18n) GetMessage(ctx context.Context, format string, args ...interface{
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Sprintf(format, args...)
|
||||
return ""
|
||||
}
|
||||
|
||||
// Wrapper returns a new router wrapper.
|
||||
|
||||
Reference in New Issue
Block a user