Add config for localeDirectionTestingOverride
This commit is contained in:
parent
a472b18d6e
commit
5acacfeb16
4 changed files with 27 additions and 37 deletions
|
@ -78,34 +78,6 @@ function getLocaleDirection(
|
|||
return 'ltr';
|
||||
}
|
||||
|
||||
function finalize(
|
||||
availableLocales: Array<string>,
|
||||
messages: LocaleMessagesType,
|
||||
backupMessages: LocaleMessagesType,
|
||||
localeName: string,
|
||||
hourCyclePreference: HourCyclePreference,
|
||||
localeDisplayNames: LocaleDisplayNames,
|
||||
logger: LoggerType
|
||||
): LocaleType {
|
||||
// We start with english, then overwrite that with anything present in locale
|
||||
const finalMessages = merge(backupMessages, messages);
|
||||
|
||||
const i18n = setupI18n(localeName, finalMessages);
|
||||
|
||||
const direction = getLocaleDirection(localeName, logger);
|
||||
logger.info(`locale: Text info direction for ${localeName}: ${direction}`);
|
||||
|
||||
return {
|
||||
availableLocales,
|
||||
i18n,
|
||||
name: localeName,
|
||||
direction,
|
||||
messages: finalMessages,
|
||||
hourCyclePreference,
|
||||
localeDisplayNames,
|
||||
};
|
||||
}
|
||||
|
||||
export function _getAvailableLocales(): Array<string> {
|
||||
return JSON.parse(
|
||||
readFileSync(
|
||||
|
@ -118,11 +90,13 @@ export function _getAvailableLocales(): Array<string> {
|
|||
export function load({
|
||||
preferredSystemLocales,
|
||||
localeOverride,
|
||||
localeDirectionTestingOverride,
|
||||
hourCyclePreference,
|
||||
logger,
|
||||
}: {
|
||||
preferredSystemLocales: Array<string>;
|
||||
localeOverride: string | null;
|
||||
localeDirectionTestingOverride: LocaleDirection | null;
|
||||
hourCyclePreference: HourCyclePreference;
|
||||
logger: LoggerType;
|
||||
}): LocaleType {
|
||||
|
@ -151,15 +125,22 @@ export function load({
|
|||
|
||||
const matchedLocaleMessages = getLocaleMessages(matchedLocale);
|
||||
const englishMessages = getLocaleMessages('en');
|
||||
const languageDisplayNames = getLocaleDisplayNames();
|
||||
const localeDisplayNames = getLocaleDisplayNames();
|
||||
|
||||
return finalize(
|
||||
// We start with english, then overwrite that with anything present in locale
|
||||
const finalMessages = merge(englishMessages, matchedLocaleMessages);
|
||||
const i18n = setupI18n(matchedLocale, finalMessages);
|
||||
const direction =
|
||||
localeDirectionTestingOverride ?? getLocaleDirection(matchedLocale, logger);
|
||||
logger.info(`locale: Text info direction for ${matchedLocale}: ${direction}`);
|
||||
|
||||
return {
|
||||
availableLocales,
|
||||
matchedLocaleMessages,
|
||||
englishMessages,
|
||||
matchedLocale,
|
||||
i18n,
|
||||
name: matchedLocale,
|
||||
direction,
|
||||
messages: finalMessages,
|
||||
hourCyclePreference,
|
||||
languageDisplayNames,
|
||||
logger
|
||||
);
|
||||
localeDisplayNames,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ import { SettingsChannel } from '../ts/main/settingsChannel';
|
|||
import { maybeParseUrl, setUrlSearchParams } from '../ts/util/url';
|
||||
import { getHeicConverter } from '../ts/workers/heicConverterMain';
|
||||
|
||||
import type { LocaleType } from './locale';
|
||||
import type { LocaleDirection, LocaleType } from './locale';
|
||||
import { load as loadLocale } from './locale';
|
||||
|
||||
import type { LoggerType } from '../ts/types/Logging';
|
||||
|
@ -144,6 +144,7 @@ const consoleLogger = createBufferedConsoleLogger();
|
|||
let logger: LoggerType | undefined;
|
||||
let preferredSystemLocales: Array<string> | undefined;
|
||||
let localeOverride: string | null | undefined;
|
||||
|
||||
let resolvedTranslationsLocale: LocaleType | undefined;
|
||||
let settingsChannel: SettingsChannel | undefined;
|
||||
|
||||
|
@ -159,6 +160,11 @@ const development =
|
|||
|
||||
const ciMode = config.get<'full' | 'benchmark' | false>('ciMode');
|
||||
const forcePreloadBundle = config.get<boolean>('forcePreloadBundle');
|
||||
const localeDirectionTestingOverride = config.has(
|
||||
'localeDirectionTestingOverride'
|
||||
)
|
||||
? config.get<LocaleDirection>('localeDirectionTestingOverride')
|
||||
: null;
|
||||
|
||||
const preventDisplaySleepService = new PreventDisplaySleepService(
|
||||
powerSaveBlocker
|
||||
|
@ -1858,6 +1864,7 @@ app.on('ready', async () => {
|
|||
resolvedTranslationsLocale = loadLocale({
|
||||
preferredSystemLocales,
|
||||
localeOverride,
|
||||
localeDirectionTestingOverride,
|
||||
hourCyclePreference,
|
||||
logger: getLogger(),
|
||||
});
|
||||
|
|
|
@ -27,6 +27,7 @@ describe('locale', async () => {
|
|||
const actualLocale = await load({
|
||||
preferredSystemLocales,
|
||||
localeOverride: null,
|
||||
localeDirectionTestingOverride: null,
|
||||
hourCyclePreference: HourCyclePreference.UnknownPreference,
|
||||
logger,
|
||||
});
|
||||
|
|
|
@ -200,6 +200,7 @@ describe('createTemplate', () => {
|
|||
const { i18n } = loadLocale({
|
||||
preferredSystemLocales: ['en'],
|
||||
localeOverride: null,
|
||||
localeDirectionTestingOverride: null,
|
||||
hourCyclePreference: HourCyclePreference.UnknownPreference,
|
||||
logger: {
|
||||
fatal: stub().throwsArg(0),
|
||||
|
|
Loading…
Reference in a new issue