INNER CODE UNIT · TypeScript

translatedLocales

hsr88/mouzi · website/src/i18n/index.ts:2

export const translatedLocales = locales.filter((locale) => locale !== 'en');
export type Locale = (typeof locales)[number];

export const localeNames: Record<Locale, string> = {
  en: 'English', es: 'Español', pl: 'Polski', de: 'Deutsch', fr: 'Français', it: 'Italiano',
};

export function localeFromPath(pathname: string): Locale {
  const candidate = pathname.split('/').filter(Boolean)[0]?.replace(/\.html$/, '') as Locale | undefined;
  return candidate && locales.includes(candidate) ? candidate : 'en';
}

export function stripLocale(pathname: string): string {
  const locale = localeFromPath(pathname);
  const cleanPath = pathname.replace(/\.html$/, '');
  if (locale === 'en') return cleanPath || '/';
  const stripped = cleanPath.replace(new RegExp(`^/${locale}(?=/|$)`), '');
  return stripped || '/';

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…