[MM-27919] Allow i18n and resources to be loaded using an environment variable (#15341)

* [MM-27919] Allow i18n and resources to be loaded using an environment variable

* Improve error message

* Modify environment variable name to be less ambiguous

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Miguel de la Cruz
2020-08-25 17:29:40 +02:00
коммит произвёл GitHub
родитель 8ee5113a30
Коммит 49a75059c5
2 изменённых файлов: 27 добавлений и 11 удалений

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

@@ -7,6 +7,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"strings"
@@ -32,7 +33,13 @@ func TranslationsPreInit() error {
// segfault trying to handle the error, and the untranslated IDs are strictly better.
T = TfuncWithFallback("en")
TDefault = TfuncWithFallback("en")
return InitTranslationsWithDir("i18n")
translationsDir := "i18n"
if mattermostPath := os.Getenv("MM_SERVER_PATH"); mattermostPath != "" {
translationsDir = filepath.Join(mattermostPath, "i18n")
}
return InitTranslationsWithDir(translationsDir)
}
func InitTranslations(localizationSettings model.LocalizationSettings) error {
@@ -46,7 +53,7 @@ func InitTranslations(localizationSettings model.LocalizationSettings) error {
func InitTranslationsWithDir(dir string) error {
i18nDirectory, found := fileutils.FindDirRelBinary(dir)
if !found {
return fmt.Errorf("Unable to find i18n directory")
return fmt.Errorf(fmt.Sprintf("Unable to find i18n directory at %q", dir))
}
files, _ := ioutil.ReadDir(i18nDirectory)