aboutsummaryrefslogtreecommitdiff
path: root/examples/docs/src/languages.ts
blob: 405b6921ca476aae02a5796099b3d457a63757c0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
import { KNOWN_LANGUAGES, KNOWN_LANGUAGE_CODES } from './config';
export { KNOWN_LANGUAGES, KNOWN_LANGUAGE_CODES };

export const langPathRegex = /\/([a-z]{2}-?[A-Z]{0,2})\//;

export function getLanguageFromURL(pathname: string) {
	const langCodeMatch = pathname.match(langPathRegex);
	const langCode = langCodeMatch ? langCodeMatch[1] : 'en';
	return langCode as typeof KNOWN_LANGUAGE_CODES[number];
}