1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-06-25 10:25:36 +02:00

Merge branch 'main' into vault/pm-5273

This commit is contained in:
Carlos Gonçalves 2024-03-14 12:09:19 +00:00
commit cf69056e48
No known key found for this signature in database
GPG Key ID: 8147F618E732EF25
9 changed files with 18 additions and 7 deletions

View File

@ -26,6 +26,7 @@ export class InitService {
init() {
return async () => {
await this.stateService.init();
await this.i18nService.init();
if (!BrowserPopupUtils.inPopup(window)) {
window.document.body.classList.add("body-full");

View File

@ -264,7 +264,7 @@ export class SettingsComponent implements OnInit {
enableDuckDuckGoBrowserIntegration:
await this.stateService.getEnableDuckDuckGoBrowserIntegration(),
theme: await firstValueFrom(this.themeStateService.selectedTheme$),
locale: await firstValueFrom(this.i18nService.locale$),
locale: await firstValueFrom(this.i18nService.userSetLocale$),
};
this.form.setValue(initialValues, { emitEvent: false });

View File

@ -19,8 +19,6 @@ import { ContainerService } from "@bitwarden/common/platform/services/container.
import { EventUploadService } from "@bitwarden/common/services/event/event-upload.service";
import { VaultTimeoutService } from "@bitwarden/common/services/vault-timeout/vault-timeout.service";
import { I18nService } from "../core/i18n.service";
@Injectable()
export class InitService {
constructor(
@ -52,7 +50,7 @@ export class InitService {
setTimeout(() => this.notificationsService.init(), 3000);
await this.vaultTimeoutService.init(true);
await (this.i18nService as I18nService).init();
await this.i18nService.init();
(this.eventUploadService as EventUploadService).init(true);
this.twoFactorService.init();
const htmlEl = this.win.document.documentElement;

View File

@ -8,6 +8,7 @@ import eng from "../../../locales/en/messages.json";
class PreloadedEnglishI18nService extends TranslationService implements I18nService {
translationLocale = "en";
userSetLocale$: Observable<string | undefined> = of("en");
locale$: Observable<string> = of("en");
constructor() {
super("en", "", () => {

View File

@ -141,7 +141,7 @@ export class PreferencesComponent implements OnInit {
),
enableFavicons: !(await this.settingsService.getDisableFavicon()),
theme: await firstValueFrom(this.themeStateService.selectedTheme$),
locale: (await firstValueFrom(this.i18nService.locale$)) ?? null,
locale: (await firstValueFrom(this.i18nService.userSetLocale$)) ?? null,
};
this.startingLocale = initialFormValues.locale;
this.form.setValue(initialFormValues, { emitEvent: false });

View File

@ -3,6 +3,8 @@ import { Observable } from "rxjs";
import { TranslationService } from "./translation.service";
export abstract class I18nService extends TranslationService {
userSetLocale$: Observable<string | undefined>;
locale$: Observable<string>;
abstract setLocale(locale: string): Promise<void>;
abstract init(): Promise<void>;
}

View File

@ -12,6 +12,7 @@ const LOCALE_KEY = new KeyDefinition<string>(TRANSLATION_DISK, "locale", {
export class I18nService extends TranslationService implements I18nServiceAbstraction {
translationLocale: string;
protected translationLocaleState: GlobalState<string>;
userSetLocale$: Observable<string | undefined>;
locale$: Observable<string>;
constructor(
@ -22,7 +23,8 @@ export class I18nService extends TranslationService implements I18nServiceAbstra
) {
super(systemLanguage, localesDirectory, getLocalesJson);
this.translationLocaleState = globalStateProvider.get(LOCALE_KEY);
this.locale$ = this.translationLocaleState.state$.pipe(map((locale) => locale ?? null));
this.userSetLocale$ = this.translationLocaleState.state$;
this.locale$ = this.userSetLocale$.pipe(map((locale) => locale ?? this.translationLocale));
}
async setLocale(locale: string): Promise<void> {

View File

@ -173,7 +173,9 @@ export class DefaultActiveUserState<T> implements ActiveUserState<T> {
),
);
if (userId == null) {
throw new Error("No active user at this time.");
throw new Error(
`Error storing ${this.keyDefinition.fullName} for the active user: No active user at this time.`,
);
}
const fullKey = this.keyDefinition.buildKey(userId);
return [

View File

@ -3,6 +3,7 @@ import { Observable } from "rxjs";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
export class I18nMockService implements I18nService {
userSetLocale$: Observable<string | undefined>;
locale$: Observable<string>;
supportedTranslationLocales: string[];
translationLocale: string;
@ -38,4 +39,8 @@ export class I18nMockService implements I18nService {
async setLocale(locale: string): Promise<void> {
throw new Error("Method not implemented.");
}
init(): Promise<void> {
throw new Error("Method not implemented.");
}
}