mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
(mostly) redundant localization on frontend
This commit is contained in:
@@ -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
|
||||
|
||||
16
web/projects/shared/src/i18n/localize.pipe.ts
Normal file
16
web/projects/shared/src/i18n/localize.pipe.ts
Normal 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)
|
||||
}
|
||||
}
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user