
* fix video url * update deploy script for using rsync * remove delete from script * translate resources page * fix images dimensions and favicon * add css optimization plugin and improve images * update project dependencies * refactor lang * post translated to spanish * fix metadata * update dependencies * update dependencies * update dependencies * update to Astro 5.x * format index.astro * Migrate content layer to Astro V5 * Fix duplicated variable
22 lines
645 B
TypeScript
22 lines
645 B
TypeScript
import { ui, defaultLang, showDefaultLang } from '@/i18n/ui';
|
|
|
|
export type lang = 'en' | 'es';
|
|
|
|
export function getLangFromUrl(url: URL) {
|
|
const [, lang] = url.pathname.split('/');
|
|
if (lang in ui) return lang as keyof typeof ui;
|
|
return defaultLang;
|
|
}
|
|
|
|
export function useTranslations(lang: keyof typeof ui) {
|
|
return function t(key: keyof (typeof ui)[typeof defaultLang]) {
|
|
return ui[lang][key] || ui[defaultLang][key];
|
|
};
|
|
}
|
|
|
|
export function useTranslatedPath(lang: keyof typeof ui) {
|
|
return function translatePath(path: string, l: string = lang) {
|
|
return !showDefaultLang && l === defaultLang ? path : `/${l}${path}`;
|
|
};
|
|
}
|