astro/examples/docs/src/languages.ts
2021-08-26 15:03:21 -07:00

8 lines
294 B
TypeScript

import { KNOWN_LANGUAGES } from './config.js';
export const KNOWN_LANGUAGE_CODES = Object.values(KNOWN_LANGUAGES);
export function getLanguageFromURL(pathname: string) {
const langCodeMatch = pathname.match(/\/([a-z]{2}-?[A-Z]{0,2})\//);
return langCodeMatch ? langCodeMatch[1] : 'en';
}