[MM-49265] Update translations when config is changed (#21987)

* update translations when config is changed

* wrap and return the error message

* use the configs directly instead of diff
Этот коммит содержится в:
Konstantinos Pittas
2023-01-27 01:20:04 +02:00
коммит произвёл GitHub
родитель f852237e33
Коммит 874c6269ec
3 изменённых файлов: 38 добавлений и 0 удалений

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

@@ -13,6 +13,7 @@ import (
"github.com/mattermost/mattermost-server/v6/audit"
"github.com/mattermost/mattermost-server/v6/config"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/shared/i18n"
"github.com/mattermost/mattermost-server/v6/shared/mlog"
"github.com/mattermost/mattermost-server/v6/utils"
)
@@ -184,6 +185,15 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
// If the config for default server locale has changed, reinitialize the server's translations.
if oldCfg.LocalizationSettings.DefaultServerLocale != newCfg.LocalizationSettings.DefaultServerLocale {
s := newCfg.LocalizationSettings
if err = i18n.InitTranslations(*s.DefaultServerLocale, *s.DefaultClientLocale); err != nil {
c.Err = model.NewAppError("updateConfig", "api.config.update_config.translations.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
return
}
}
diffs, err := config.Diff(oldCfg, newCfg)
if err != nil {
c.Err = model.NewAppError("updateConfig", "api.config.update_config.diff.app_error", nil, "", http.StatusInternalServerError).Wrap(err)

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

@@ -93,6 +93,30 @@ func TestCreateTeam(t *testing.T) {
CheckForbiddenStatus(t, resp)
})
t.Run("should take under consideration the server language when creating a new team", func(t *testing.T) {
c := th.SystemAdminClient
cfg, _, err := c.GetConfig()
require.NoError(t, err)
newServerLang := "de"
cfg.LocalizationSettings.DefaultServerLocale = &newServerLang
translateFunc := i18n.GetUserTranslations(newServerLang)
_, _, err = c.UpdateConfig(cfg)
require.NoError(t, err)
team := th.CreateTeamWithClient(c)
channels, _, err := c.GetPublicChannelsForTeam(team.Id, 0, 1000, "")
require.NoError(t, err)
for _, ch := range channels {
if ch.Name == "off-topic" {
require.Equal(t, translateFunc("api.channel.create_default_channels.off_topic"), ch.DisplayName)
}
if ch.Name == "town-square" {
require.Equal(t, translateFunc("api.channel.create_default_channels.town_square"), ch.DisplayName)
}
}
})
t.Run("cloud limit reached returns 400", func(t *testing.T) {
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))

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

@@ -1534,6 +1534,10 @@
"id": "api.config.update_config.restricted_merge.app_error",
"translation": "Failed to merge given config."
},
{
"id": "api.config.update_config.translations.app_error",
"translation": "Failed to update server translations."
},
{
"id": "api.context.404.app_error",
"translation": "Sorry, we could not find the page."