added translation
This commit is contained in:
34
src/app/services/language.service.ts
Normal file
34
src/app/services/language.service.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Injectable, signal } from '@angular/core';
|
||||
import { TRANSLATIONS } from '../i18n/translations';
|
||||
|
||||
export type SupportedLang = 'en' | 'ru';
|
||||
|
||||
export const SUPPORTED_LANGS: { code: SupportedLang; label: string }[] = [
|
||||
{ code: 'en', label: 'EN' },
|
||||
{ code: 'ru', label: 'RU' },
|
||||
];
|
||||
|
||||
// All UI strings live in src/app/i18n/translations.ts
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class LanguageService {
|
||||
currentLang = signal<SupportedLang>('ru');
|
||||
|
||||
toggle() {
|
||||
this.currentLang.set(this.currentLang() === 'en' ? 'ru' : 'en');
|
||||
}
|
||||
|
||||
setLang(lang: SupportedLang) {
|
||||
this.currentLang.set(lang);
|
||||
}
|
||||
|
||||
t(key: string): string {
|
||||
const lang = this.currentLang();
|
||||
return TRANSLATIONS[lang]?.[key] ?? TRANSLATIONS['en']?.[key] ?? key;
|
||||
}
|
||||
|
||||
/** Returns the secondary content language (the one to translate INTO). */
|
||||
get contentTranslationLang(): SupportedLang {
|
||||
return this.currentLang() === 'en' ? 'ru' : 'en';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user