MM-54556: Integrate wip i18n languages (#24308)

* merge languages from https://github.com/mattermost/i18n-wip

* allow only supported server locales

* Revert "merge languages from https://github.com/mattermost/i18n-wip"

This reverts commit 36de545102faffe1e8ba943decdab04bc4f5a55c. We'll let
weblate populate these on start instead.

* copy fileutils to public/utils

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Jesse Hallam
2023-09-26 12:49:27 -04:00
коммит произвёл GitHub
родитель a838433263
Коммит 14f784a0cc
5 изменённых файлов: 455 добавлений и 5 удалений

Просмотреть файл

@@ -33,6 +33,32 @@ var T TranslateFunc
var TDefault TranslateFunc
var locales = make(map[string]string)
// supportedLocales is a hard-coded list of locales considered ready for production use. It must
// be kept in sync with ../../../../webapp/channels/src/i18n/i18n.jsx.
var supportedLocales = []string{
"de",
"en",
"en-AU",
"es",
"fr",
"it",
"hu",
"nl",
"pl",
"pt-BR",
"ro",
"sv",
"tr",
"bg",
"ru",
"uk",
"fa",
"ko",
"zh-CN",
"zh-TW",
"ja",
}
var defaultServerLocale string
var defaultClientLocale string
@@ -67,7 +93,13 @@ func initTranslationsWithDir(dir string) error {
for _, f := range files {
if filepath.Ext(f.Name()) == ".json" {
filename := f.Name()
locales[strings.Split(filename, ".")[0]] = filepath.Join(dir, filename)
locale := strings.Split(filename, ".")[0]
if !isSupportedLocale(locale) {
continue
}
locales[locale] = filepath.Join(dir, filename)
if err := i18n.LoadTranslationFile(filepath.Join(dir, filename)); err != nil {
return err
@@ -89,8 +121,13 @@ func GetTranslationFuncForDir(dir string) (TranslationFuncByLocal, error) {
continue
}
locale := strings.Split(f.Name(), ".")[0]
if !isSupportedLocale(locale) {
continue
}
filename := f.Name()
availableLocals[strings.Split(filename, ".")[0]] = filepath.Join(dir, filename)
availableLocals[locale] = filepath.Join(dir, filename)
if err := bundle.LoadTranslationFile(filepath.Join(dir, filename)); err != nil {
return nil, err
}
@@ -116,7 +153,12 @@ func GetTranslationFuncForDir(dir string) (TranslationFuncByLocal, error) {
func getTranslationsBySystemLocale() (TranslateFunc, error) {
locale := defaultServerLocale
if _, ok := locales[locale]; !ok {
mlog.Warn("Failed to load system translations for", mlog.String("locale", locale), mlog.String("attempting to fall back to default locale", defaultLocale))
mlog.Warn("Failed to load system translations for selected locale, attempting to fall back to default", mlog.String("locale", locale), mlog.String("default_locale", defaultLocale))
locale = defaultLocale
}
if !isSupportedLocale(locale) {
mlog.Warn("Selected locale is unsupported, attempting to fall back to default", mlog.String("locale", locale), mlog.String("default_locale", defaultLocale))
locale = defaultLocale
}
@@ -222,3 +264,13 @@ func IdentityTfunc() TranslateFunc {
return translationID
}
}
func isSupportedLocale(locale string) bool {
for _, supportedLocale := range supportedLocales {
if locale == supportedLocale {
return true
}
}
return false
}