refactor: add selected language signal

This commit is contained in:
2025-12-22 23:02:37 -03:00
parent 361fd6ce57
commit 71c67e23fd

View File

@@ -1,4 +1,4 @@
import { inject, Injectable } from '@angular/core'; import { inject, Injectable, signal } from '@angular/core';
import { STRINGS_INJECTOR } from '../app.config'; import { STRINGS_INJECTOR } from '../app.config';
import { Language } from '../types/Language.type'; import { Language } from '../types/Language.type';
@@ -8,9 +8,12 @@ import { Language } from '../types/Language.type';
export class LanguageManager { export class LanguageManager {
private readonly stringsDictionary = inject(STRINGS_INJECTOR); private readonly stringsDictionary = inject(STRINGS_INJECTOR);
private readonly selectedLanguage = signal<Language>('en');
readonly selectedLanguage$ = this.selectedLanguage.asReadonly();
strings = this.stringsDictionary.en; strings = this.stringsDictionary.en;
setLanguage(language: Language) { setLanguage(language: Language) {
this.selectedLanguage.set(language);
this.strings = this.stringsDictionary[language]; this.strings = this.stringsDictionary[language];
} }
} }