some changes

This commit is contained in:
john 2025-06-16 21:28:24 +02:00
parent 5e96ab6955
commit bc5c2075f4
8 changed files with 45 additions and 41 deletions

View file

@ -1,24 +0,0 @@
export interface Translations {
'auth.login.cta': string
'auth.login.register_instead': string
'auth.password.label': string
'auth.register.cta': string
'auth.register.login_instead': string
'auth.remember_me.label': string
'auth.username.label': string
'misc.loading': string
'nav.admin': string
'nav.home': string
'nav.login': string
'nav.logout': string
'nav.register': string
'post.add_media.cta': string
'post.editor.placeholder': string
'post.public.label': string
'post.submit.cta': string
}
export type TranslationKey = keyof Translations

View file

@ -0,0 +1,41 @@
import en from './translations/en.json' assert { type: 'json' }
interface Translation {
'auth.login.cta': string
'auth.login.register_instead': string
'auth.password.label': string
'auth.register.cta': string
'auth.register.login_instead': string
'auth.remember_me.label': string
'auth.username.label': string
'misc.loading': string
'nav.admin': string
'nav.home': string
'nav.login': string
'nav.logout': string
'nav.register': string
'post.add_media.cta': string
'post.editor.placeholder': string
'post.public.label': string
'post.submit.cta': string
}
export type TranslationKey = keyof Translation
export interface UseTranslations {
t: <K extends TranslationKey>(key: K) => Translation[K]
}
export function useTranslations(): UseTranslations {
// TODO somehow handle other languages (reactively)
const texts = en as Translation
function getText<K extends TranslationKey>(key: K): Translation[K] {
return texts[key] ?? key
}
return { t: getText }
}

View file

@ -1,13 +0,0 @@
import { TranslationKey, Translations } from './translationKeys.ts'
import en from './en.json' assert { type: 'json' }
export function useTranslations() {
// TODO somehow handle other languages (reactively)
const texts = en as Translations
function getText<K extends TranslationKey>(key: K): Translations[K] {
return texts[key] ?? key
}
return { t: getText }
}