This commit is contained in:
Salam-vsem
2025-05-12 20:46:39 +03:00
commit ba30833279
43 changed files with 8562 additions and 0 deletions

17
src/i18n/utils.ts Normal file
View File

@@ -0,0 +1,17 @@
import { ui } 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: keyof (typeof ui)[keyof typeof ui]) {
return ui[lang as keyof typeof ui]?.[key] || ui[i18n!.defaultLocale as keyof typeof ui][key];
};
}