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';
|
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> {
|
export function _getAvailableLocales(): Array<string> {
|
||||||
return JSON.parse(
|
return JSON.parse(
|
||||||
readFileSync(
|
readFileSync(
|
||||||
|
@ -118,11 +90,13 @@ export function _getAvailableLocales(): Array<string> {
|
||||||
export function load({
|
export function load({
|
||||||
preferredSystemLocales,
|
preferredSystemLocales,
|
||||||
localeOverride,
|
localeOverride,
|
||||||
|
localeDirectionTestingOverride,
|
||||||
hourCyclePreference,
|
hourCyclePreference,
|
||||||
logger,
|
logger,
|
||||||
}: {
|
}: {
|
||||||
preferredSystemLocales: Array<string>;
|
preferredSystemLocales: Array<string>;
|
||||||
localeOverride: string | null;
|
localeOverride: string | null;
|
||||||
|
localeDirectionTestingOverride: LocaleDirection | null;
|
||||||
hourCyclePreference: HourCyclePreference;
|
hourCyclePreference: HourCyclePreference;
|
||||||
logger: LoggerType;
|
logger: LoggerType;
|
||||||
}): LocaleType {
|
}): LocaleType {
|
||||||
|
@ -151,15 +125,22 @@ export function load({
|
||||||
|
|
||||||
const matchedLocaleMessages = getLocaleMessages(matchedLocale);
|
const matchedLocaleMessages = getLocaleMessages(matchedLocale);
|
||||||
const englishMessages = getLocaleMessages('en');
|
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,
|
availableLocales,
|
||||||
matchedLocaleMessages,
|
i18n,
|
||||||
englishMessages,
|
name: matchedLocale,
|
||||||
matchedLocale,
|
direction,
|
||||||
|
messages: finalMessages,
|
||||||
hourCyclePreference,
|
hourCyclePreference,
|
||||||
languageDisplayNames,
|
localeDisplayNames,
|
||||||
logger
|
};
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ import { SettingsChannel } from '../ts/main/settingsChannel';
|
||||||
import { maybeParseUrl, setUrlSearchParams } from '../ts/util/url';
|
import { maybeParseUrl, setUrlSearchParams } from '../ts/util/url';
|
||||||
import { getHeicConverter } from '../ts/workers/heicConverterMain';
|
import { getHeicConverter } from '../ts/workers/heicConverterMain';
|
||||||
|
|
||||||
import type { LocaleType } from './locale';
|
import type { LocaleDirection, LocaleType } from './locale';
|
||||||
import { load as loadLocale } from './locale';
|
import { load as loadLocale } from './locale';
|
||||||
|
|
||||||
import type { LoggerType } from '../ts/types/Logging';
|
import type { LoggerType } from '../ts/types/Logging';
|
||||||
|
@ -144,6 +144,7 @@ const consoleLogger = createBufferedConsoleLogger();
|
||||||
let logger: LoggerType | undefined;
|
let logger: LoggerType | undefined;
|
||||||
let preferredSystemLocales: Array<string> | undefined;
|
let preferredSystemLocales: Array<string> | undefined;
|
||||||
let localeOverride: string | null | undefined;
|
let localeOverride: string | null | undefined;
|
||||||
|
|
||||||
let resolvedTranslationsLocale: LocaleType | undefined;
|
let resolvedTranslationsLocale: LocaleType | undefined;
|
||||||
let settingsChannel: SettingsChannel | undefined;
|
let settingsChannel: SettingsChannel | undefined;
|
||||||
|
|
||||||
|
@ -159,6 +160,11 @@ const development =
|
||||||
|
|
||||||
const ciMode = config.get<'full' | 'benchmark' | false>('ciMode');
|
const ciMode = config.get<'full' | 'benchmark' | false>('ciMode');
|
||||||
const forcePreloadBundle = config.get<boolean>('forcePreloadBundle');
|
const forcePreloadBundle = config.get<boolean>('forcePreloadBundle');
|
||||||
|
const localeDirectionTestingOverride = config.has(
|
||||||
|
'localeDirectionTestingOverride'
|
||||||
|
)
|
||||||
|
? config.get<LocaleDirection>('localeDirectionTestingOverride')
|
||||||
|
: null;
|
||||||
|
|
||||||
const preventDisplaySleepService = new PreventDisplaySleepService(
|
const preventDisplaySleepService = new PreventDisplaySleepService(
|
||||||
powerSaveBlocker
|
powerSaveBlocker
|
||||||
|
@ -1858,6 +1864,7 @@ app.on('ready', async () => {
|
||||||
resolvedTranslationsLocale = loadLocale({
|
resolvedTranslationsLocale = loadLocale({
|
||||||
preferredSystemLocales,
|
preferredSystemLocales,
|
||||||
localeOverride,
|
localeOverride,
|
||||||
|
localeDirectionTestingOverride,
|
||||||
hourCyclePreference,
|
hourCyclePreference,
|
||||||
logger: getLogger(),
|
logger: getLogger(),
|
||||||
});
|
});
|
||||||
|
|
|
@ -27,6 +27,7 @@ describe('locale', async () => {
|
||||||
const actualLocale = await load({
|
const actualLocale = await load({
|
||||||
preferredSystemLocales,
|
preferredSystemLocales,
|
||||||
localeOverride: null,
|
localeOverride: null,
|
||||||
|
localeDirectionTestingOverride: null,
|
||||||
hourCyclePreference: HourCyclePreference.UnknownPreference,
|
hourCyclePreference: HourCyclePreference.UnknownPreference,
|
||||||
logger,
|
logger,
|
||||||
});
|
});
|
||||||
|
|
|
@ -200,6 +200,7 @@ describe('createTemplate', () => {
|
||||||
const { i18n } = loadLocale({
|
const { i18n } = loadLocale({
|
||||||
preferredSystemLocales: ['en'],
|
preferredSystemLocales: ['en'],
|
||||||
localeOverride: null,
|
localeOverride: null,
|
||||||
|
localeDirectionTestingOverride: null,
|
||||||
hourCyclePreference: HourCyclePreference.UnknownPreference,
|
hourCyclePreference: HourCyclePreference.UnknownPreference,
|
||||||
logger: {
|
logger: {
|
||||||
fatal: stub().throwsArg(0),
|
fatal: stub().throwsArg(0),
|
||||||
|
|
Loading…
Reference in a new issue