Improve performance of mock tests

This commit is contained in:
Jamie Kyle 2024-02-29 14:01:12 -08:00 committed by GitHub
parent ea9a7385d6
commit 9c072c5bc1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 18 additions and 64 deletions

View file

@ -84,7 +84,13 @@ function normalizeSubstitutions(
return;
}
const normalized: ReplacementValuesType = {};
for (const [key, value] of Object.entries(substitutions)) {
const keys = Object.keys(substitutions);
if (keys.length === 0) {
return;
}
for (let i = 0; i < keys.length; i += 1) {
const key = keys[i];
const value = substitutions[key];
if (typeof value === 'string') {
normalized[key] = bidiIsolate(value);
} else {
@ -108,26 +114,11 @@ export function setupI18n(
const intl = createCachedIntl(locale, filterLegacyMessages(messages));
const localizer: LocalizerType = (key, substitutions) => {
strictAssert(
!localizer.isLegacyFormat(key),
`i18n: Legacy message format is no longer supported "${key}"`
);
strictAssert(
!Array.isArray(substitutions),
`i18n: Substitutions must be an object for ICU message "${key}"`
);
const result = intl.formatMessage(
{ id: key },
normalizeSubstitutions(substitutions)
);
strictAssert(
typeof result === 'string',
'i18n: Formatted translation result must be a string, must use <Intl/> component to render JSX'
);
strictAssert(result !== key, `i18n: missing translation for "${key}"`);
return result;
@ -136,9 +127,6 @@ export function setupI18n(
localizer.getIntl = () => {
return intl;
};
localizer.isLegacyFormat = (key: string) => {
return !key.startsWith('icu:');
};
localizer.getLocale = () => locale;
localizer.getLocaleMessages = () => messages;
localizer.getLocaleDirection = () => {