Files
real-skill-landing/src/i18n/utils.ts
2025-05-15 00:59:58 +03:00

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]
}
}