[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
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
f852237e33
Коммит
874c6269ec
@@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/v6/audit"
|
"github.com/mattermost/mattermost-server/v6/audit"
|
||||||
"github.com/mattermost/mattermost-server/v6/config"
|
"github.com/mattermost/mattermost-server/v6/config"
|
||||||
"github.com/mattermost/mattermost-server/v6/model"
|
"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/shared/mlog"
|
||||||
"github.com/mattermost/mattermost-server/v6/utils"
|
"github.com/mattermost/mattermost-server/v6/utils"
|
||||||
)
|
)
|
||||||
@@ -184,6 +185,15 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
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)
|
diffs, err := config.Diff(oldCfg, newCfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Err = model.NewAppError("updateConfig", "api.config.update_config.diff.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
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)
|
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) {
|
t.Run("cloud limit reached returns 400", func(t *testing.T) {
|
||||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||||
|
|
||||||
|
|||||||
@@ -1534,6 +1534,10 @@
|
|||||||
"id": "api.config.update_config.restricted_merge.app_error",
|
"id": "api.config.update_config.restricted_merge.app_error",
|
||||||
"translation": "Failed to merge given config."
|
"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",
|
"id": "api.context.404.app_error",
|
||||||
"translation": "Sorry, we could not find the page."
|
"translation": "Sorry, we could not find the page."
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user