1
0
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:
Gerasimos (Makis) Maropoulos
2020-04-30 16:16:43 +03:00
parent 3fbf15d576
commit c3543528cf
6 changed files with 105 additions and 55 deletions

View File

@@ -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.