Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | import { ca } from './ca';
import { en } from './en';
import { es } from './es';
import type { Translations } from './types';
const translations: Record<string, Translations> = { en, ca, es };
export const languages = {
en: 'English',
ca: 'Català',
es: 'Español',
};
export const defaultLang = 'en';
export type Lang = keyof typeof languages;
function normalizeLang(lang: string): Lang {
return Object.hasOwn(languages, lang) ? (lang as Lang) : defaultLang;
}
export function useTranslations(lang: string) {
return translations[normalizeLang(lang)];
}
export function localizedPath(lang: string, path: string) {
const normalized = normalizeLang(lang);
if (normalized === defaultLang) return path;
return `/${normalized}${path}`;
}
|