mirror of
https://github.com/bitwarden/browser.git
synced 2024-09-28 04:08:47 +02:00
f4150ffda6
* Use state provider to store preferred language * migrate preferred language * Use new i18n provider to get LOCAL_ID * Fix preloaded english i18n This is a mock service that forces english translations, it doesn't need the i18n interface that allows changing of locales. * PR improvements * Fixup merge
40 lines
985 B
TypeScript
40 lines
985 B
TypeScript
import { MigrationHelper } from "../migration-helper";
|
|
import { Migrator } from "../migrator";
|
|
|
|
type ExpectedGlobal = {
|
|
locale?: string;
|
|
};
|
|
|
|
export const LOCALE_KEY = {
|
|
key: "locale",
|
|
stateDefinition: {
|
|
name: "translation",
|
|
},
|
|
};
|
|
|
|
export class PreferredLanguageMigrator extends Migrator<31, 32> {
|
|
async migrate(helper: MigrationHelper): Promise<void> {
|
|
// global state
|
|
const global = await helper.get<ExpectedGlobal>("global");
|
|
if (!global?.locale) {
|
|
return;
|
|
}
|
|
|
|
await helper.setToGlobal(LOCALE_KEY, global.locale);
|
|
delete global.locale;
|
|
await helper.set("global", global);
|
|
}
|
|
|
|
async rollback(helper: MigrationHelper): Promise<void> {
|
|
const locale = await helper.getFromGlobal<string>(LOCALE_KEY);
|
|
|
|
if (!locale) {
|
|
return;
|
|
}
|
|
const global = (await helper.get<ExpectedGlobal>("global")) ?? {};
|
|
global.locale = locale;
|
|
await helper.set("global", global);
|
|
await helper.setToGlobal(LOCALE_KEY, null);
|
|
}
|
|
}
|