added translation

This commit is contained in:
sdarbinyan
2026-02-20 09:01:02 +04:00
parent 083b270c74
commit 6850a911f3
22 changed files with 1219 additions and 136 deletions

View 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';
}
}