blob: 25eecbeb5bfcbb7eb7b95e9100d5d2eeb0c3eedc [file] [edit]
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import * as i18n from '../core/i18n/i18n.js';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore TSC is not able to find type definitions but this error does not always happen
// eslint-disable-next-line @devtools/es-modules-import
import EnUsLocaleData from '../core/i18n/locales/en-US.json' with {type : 'json'};
export async function initializeGlobalLocaleVars(): Promise<void> {
// Expose the locale.
i18n.DevToolsLocale.DevToolsLocale.instance({
create: true,
data: {
navigatorLanguage: 'en-US',
settingLanguage: 'en-US',
lookupClosestDevToolsLocale: () => 'en-US',
},
});
if (i18n.i18n.hasLocaleDataForTest('en-US')) {
return;
}
i18n.i18n.registerLocaleDataForTest('en-US', EnUsLocaleData);
}
export function deinitializeGlobalLocaleVars(): void {
i18n.DevToolsLocale.DevToolsLocale.removeInstance();
}
export function setupLocaleHooks(): void {
beforeEach(async () => await initializeGlobalLocaleVars());
afterEach(deinitializeGlobalLocaleVars);
}