(mostly) redundant localization on frontend

This commit is contained in:
Aiden McClelland
2026-01-21 12:46:32 -07:00
parent 3828b03790
commit 35545056e7
15 changed files with 56 additions and 20 deletions

View File

@@ -1,6 +1,7 @@
import { inject, Injectable, signal } from '@angular/core'
import { TuiLanguageName, TuiLanguageSwitcherService } from '@taiga-ui/i18n'
import { I18N, I18N_LOADER, I18N_STORAGE } from './i18n.providers'
import { T } from '@start9labs/start-sdk'
export const languages = ['en_US', 'es_ES', 'de_DE', 'fr_FR', 'pl_PL'] as const
export type Languages = (typeof languages)[number]
@@ -37,6 +38,14 @@ export class i18nService extends TuiLanguageSwitcherService {
)
}
localize(string: T.LocaleString): string {
if (typeof string === 'string') return string
return (
string[this.lang] ?? string['en_US'] ?? Object.values(string)[0] ?? ''
)
}
setLang(language: Languages = 'en_US'): void {
const tuiLang = LANGUAGE_TO_TUI[language]
const current = this.language

View File

@@ -0,0 +1,16 @@
import { inject, Injectable, Pipe, PipeTransform } from '@angular/core'
import { i18nService } from './i18n.service'
import { T } from '@start9labs/start-sdk'
@Pipe({
name: 'localize',
pure: false,
})
@Injectable({ providedIn: 'root' })
export class LocalizePipe implements PipeTransform {
private readonly i18nService = inject(i18nService)
transform(string: T.LocaleString): string {
return this.i18nService.localize(string)
}
}

View File

@@ -18,6 +18,7 @@ export * from './directives/safe-links.directive'
export * from './i18n/i18n.pipe'
export * from './i18n/i18n.providers'
export * from './i18n/i18n.service'
export * from './i18n/localize.pipe'
export * from './pipes/exver/exver.module'
export * from './pipes/exver/exver.pipe'