astro-reactive-form/apps/docs/src/languages.ts
Lalit f79ce72a1c
chore(apps): Setup prettier + eslint for all our apps (#254)
* chore(apps): setup prettier + eslint for all our apps

* fix(docs): Fixed the use of implicit any type

* chore(apps): Added .eslintignore files
2023-01-14 10:40:40 +01:00

10 lines
406 B
TypeScript

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];
}