[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>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
8ee5113a30
Коммит
49a75059c5
@@ -36,17 +36,26 @@ type testResourceDetails struct {
|
||||
action int8
|
||||
}
|
||||
|
||||
// commonBaseSearchPaths is a custom version of what fileutils exposes. At some point, consolidate.
|
||||
var commonBaseSearchPaths = []string{
|
||||
".",
|
||||
"..",
|
||||
"../..",
|
||||
"../../..",
|
||||
"../../../..",
|
||||
// getCommonBaseSearchPaths() is a custom version of what fileutils exposes. At some point, consolidate.
|
||||
func getCommonBaseSearchPaths() []string {
|
||||
paths := []string{
|
||||
".",
|
||||
"..",
|
||||
"../..",
|
||||
"../../..",
|
||||
"../../../..",
|
||||
}
|
||||
|
||||
// this enables the server to be used in tests from a different repository
|
||||
if mmPath := os.Getenv("MM_SERVER_PATH"); mmPath != "" {
|
||||
paths = append(paths, mmPath)
|
||||
}
|
||||
|
||||
return paths
|
||||
}
|
||||
|
||||
func findFile(path string) string {
|
||||
return fileutils.FindPath(path, commonBaseSearchPaths, func(fileInfo os.FileInfo) bool {
|
||||
return fileutils.FindPath(path, getCommonBaseSearchPaths(), func(fileInfo os.FileInfo) bool {
|
||||
return !fileInfo.IsDir()
|
||||
})
|
||||
}
|
||||
@@ -61,7 +70,7 @@ func findDir(dir string) (string, bool) {
|
||||
return path.Dir(srcPath), true
|
||||
}
|
||||
|
||||
found := fileutils.FindPath(dir, commonBaseSearchPaths, func(fileInfo os.FileInfo) bool {
|
||||
found := fileutils.FindPath(dir, getCommonBaseSearchPaths(), func(fileInfo os.FileInfo) bool {
|
||||
return fileInfo.IsDir()
|
||||
})
|
||||
if found == "" {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Ссылка в новой задаче
Block a user