Backport i18n packaging and locale fallback fixes (#38148)

* Package only the locale catalogs from server/i18n

release.mk copied server/i18n wholesale into the distribution. Everything in
that directory today is a catalog, so it made no difference -- but the server
loader, mmgotool and the sync test all already filter the directory to *.json,
and packaging was the one consumer that did not.

Copy the catalogs explicitly so documentation and any other non-catalog file
placed alongside them stays out of the release bundle.

* Validate the language fallback in display settings

user_settings_display reads getLanguageInfo(userLocale).name without a guard,
and its container fell back to config.DefaultClientLocale without checking
that value resolves. Nothing in the webapp guaranteed it did.

In practice it does today: fixInvalidLocales runs on every config load and
resets DefaultClientLocale to en when it is not in the supported set, so the
dereference cannot currently throw. That invariant lives three layers away in
Go, is silent when it fires, and is one refactor from not holding -- and the
cost of not depending on it is a two-line fallback.

So the container now re-checks the default and drops to
General.DEFAULT_LOCALE, matching what getCurrentLocale already does when the
current locale is unavailable.

Adds index.test.tsx covering the container's locale resolution: a supported
user locale is kept, an unsupported one falls back to DefaultClientLocale, and
an unsupported DefaultClientLocale -- or one excluded by AvailableLocales --
still resolves to something getLanguageInfo can look up. Two of the four fail
without the change.
This commit is contained in:
Jesse Hallam
2026-08-26 19:41:10 +00:00
committed by GitHub
parent c93955ad7c
commit 9ea90ca862
3 changed files with 82 additions and 1 deletions
+2 -1
View File
@@ -188,7 +188,8 @@ package-prep: setup-go-work
cp -RL fonts $(DIST_PATH)
cp -RL templates $(DIST_PATH)
rm -rf $(DIST_PATH)/templates/*.mjml $(DIST_PATH)/templates/partials/
cp -RL i18n $(DIST_PATH)
mkdir -p $(DIST_PATH)/i18n
cp -L i18n/*.json $(DIST_PATH)/i18n
@# Disable developer settings
sed -i'' -e 's|"ConsoleLevel": "DEBUG"|"ConsoleLevel": "INFO"|g' $(DIST_PATH)/config/config.json
@@ -0,0 +1,72 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import type {UserProfile} from '@mattermost/types/users';
import {getLanguageInfo} from 'i18n/i18n';
import mergeObjects from 'packages/mattermost-redux/test/merge_objects';
import {TestHelper} from 'utils/test_helper';
import type {GlobalState} from 'types/store';
import {makeMapStateToProps} from './index';
describe('components/user_settings/display/index', () => {
const user = TestHelper.getUserMock({id: 'user_id', locale: 'de'});
const baseState = {
entities: {
general: {
config: {
DefaultClientLocale: 'en',
},
license: {},
},
users: {
currentUserId: 'user_id',
profiles: {user_id: user},
},
preferences: {myPreferences: {}},
teams: {teams: {}, myMembers: {}},
channels: {channels: {}, myMembers: {}},
},
} as unknown as GlobalState;
const ownProps = {adminMode: false, user} as {adminMode: boolean; user: UserProfile};
function userLocaleFor(state: GlobalState, locale: string) {
const mapStateToProps = makeMapStateToProps();
return mapStateToProps(state, {...ownProps, user: {...user, locale}}).userLocale;
}
test('keeps a supported user locale', () => {
expect(userLocaleFor(baseState, 'de')).toBe('de');
});
test('falls back to DefaultClientLocale when the user locale is not supported', () => {
expect(userLocaleFor(baseState, 'cs')).toBe('en');
});
test('falls back to English when DefaultClientLocale is not supported either', () => {
// fixInvalidLocales normalizes this server side, but the settings modal
// reads .name off the result without a guard, so the fallback has to
// resolve on its own.
const state = mergeObjects(baseState, {
entities: {general: {config: {DefaultClientLocale: 'cs'}}},
});
const userLocale = userLocaleFor(state, 'cs');
expect(userLocale).toBe('en');
expect(getLanguageInfo(userLocale)).toBeDefined();
});
test('falls back to English when AvailableLocales excludes DefaultClientLocale', () => {
const state = mergeObjects(baseState, {
entities: {general: {config: {AvailableLocales: 'fr', DefaultClientLocale: 'cs'}}},
});
const userLocale = userLocaleFor(state, 'de');
expect(userLocale).toBe('en');
expect(getLanguageInfo(userLocale)).toBeDefined();
});
});
@@ -11,6 +11,7 @@ import {CollapsedThreads} from '@mattermost/types/config';
import {savePreferences} from 'mattermost-redux/actions/preferences';
import {autoUpdateTimezone} from 'mattermost-redux/actions/timezone';
import {patchUser, updateMe} from 'mattermost-redux/actions/users';
import {General} from 'mattermost-redux/constants';
import {getConfig, getLicense} from 'mattermost-redux/selectors/entities/general';
import {
get,
@@ -57,10 +58,17 @@ export function makeMapStateToProps() {
lastActiveDisplay = false;
}
// DefaultClientLocale is normalized to a supported locale server side by
// fixInvalidLocales, but user_settings_display reads the name off this
// value without a guard, so don't rely on an invariant three layers away
// to keep the settings modal from throwing.
let userLocale = props.user.locale;
if (!isLanguageAvailable(state, userLocale)) {
userLocale = config.DefaultClientLocale as string;
}
if (!isLanguageAvailable(state, userLocale)) {
userLocale = General.DEFAULT_LOCALE;
}
return {
lockTeammateNameDisplay,