0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-30 22:03:56 -05:00
astro/examples/docs/src/languages.ts

20 lines
576 B
TypeScript
Raw Normal View History

2021-08-13 19:58:00 -05:00
export const LANGUAGE_NAMES = {
English: 'en',
};
export const KNOWN_LANGUAGES = Object.values(LANGUAGE_NAMES);
export const langPathRegex = new RegExp(`\/(${KNOWN_LANGUAGES.join('|')})\/`);
export const getLanguageDetails = () => {
// @ts-ignore
let newLangWithRegion = (window.navigator.userLanguage || window.navigator.language || 'en-US').substr(0, 5);
let newLang = newLangWithRegion.substr(0, 2);
let actualDest = window.location.pathname.replace(langPathRegex, '/');
return {
newLangWithRegion,
newLang,
langPathRegex,
actualDest,
};
};