Skip to content

Commit

Permalink
fix(web): i18n explicit lang ignored (authelia#3961)
Browse files Browse the repository at this point in the history
This fixes an issue where explicit languages such as nl-NL, pt-PT, zh-CH, and zh-TW are ignored even though they're supported.
  • Loading branch information
james-d-elliott authored Sep 5, 2022
1 parent 9c5a8b7 commit cd9bfe3
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 8 deletions.
3 changes: 3 additions & 0 deletions crowdin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ files:
"en-EN": en
"es-ES": es
"fr-FR": fr
"nl-NL": nl
"pt-PT": pt
"ru-RU": ru
"zh-CH": zh
...
22 changes: 19 additions & 3 deletions internal/server/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http"
"path"
"path/filepath"
"strings"

"github.com/valyala/fasthttp"

Expand Down Expand Up @@ -71,8 +72,23 @@ func newLocalesEmbeddedHandler() (handler fasthttp.RequestHandler) {
entries, err := locales.ReadDir("locales")
if err == nil {
for _, entry := range entries {
if entry.IsDir() && len(entry.Name()) == 2 {
languages = append(languages, entry.Name())
if entry.IsDir() {
var lng string

switch len(entry.Name()) {
case 2:
lng = entry.Name()
case 0:
continue
default:
lng = strings.SplitN(entry.Name(), "-", 2)[0]
}

if utils.IsStringInSlice(lng, languages) {
continue
}

languages = append(languages, lng)
}
}
}
Expand All @@ -94,7 +110,7 @@ func newLocalesEmbeddedHandler() (handler fasthttp.RequestHandler) {
var data []byte

if data, err = locales.ReadFile(fmt.Sprintf("locales/%s/%s.json", locale, namespace)); err != nil {
if variant != "" && utils.IsStringInSliceFold(language, languages) {
if utils.IsStringInSliceFold(language, languages) {
data = []byte("{}")
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 6 additions & 5 deletions web/src/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ i18n.use(Backend)
de: ["en"],
es: ["en"],
fr: ["en"],
"nl-NL": ["en"],
"pt-PT": ["en"],
nl: ["en"],
pt: ["en"],
ru: ["en"],
sv: ["en"],
"sv-SE": ["sv", "en"],
"zh-CN": ["en"],
"zh-TW": ["en"],
zh: ["en"],
"zh-CN": ["zh", "en"],
"zh-TW": ["zh", "en"],
},
supportedLngs: ["en", "de", "es", "fr", "nl-NL", "pt-PT", "ru", "sv", "sv-SE", "zh-CN", "zh-TW"],
supportedLngs: ["en", "de", "es", "fr", "nl", "pt", "ru", "sv", "sv-SE", "zh", "zh-CN", "zh-TW"],
lowerCaseLng: false,
nonExplicitSupportedLngs: true,
interpolation: {
Expand Down

0 comments on commit cd9bfe3

Please sign in to comment.