mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 01:33:33 +00:00
Merge branch 'main' into vault/pm-5273
This commit is contained in:
@@ -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>;
|
||||
}
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -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 [
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user