18 lines
456 B
TypeScript
18 lines
456 B
TypeScript
import { ui, type TranslationKey } from './ui'
|
|
|
|
import { i18n } from 'astro:config/client'
|
|
|
|
export function getLangFromUrl(url: URL) {
|
|
const [, lang] = url.pathname.split('/')
|
|
|
|
if (lang in ui) return lang as keyof typeof ui
|
|
|
|
return i18n!.defaultLocale
|
|
}
|
|
|
|
export function useTranslations(lang?: string) {
|
|
return function t(key: TranslationKey) {
|
|
return ui[lang as keyof typeof ui]?.[key] || ui[i18n!.defaultLocale as keyof typeof ui][key]
|
|
}
|
|
}
|