mirror of
https://github.com/withastro/astro.git
synced 2024-12-30 22:03:56 -05:00
20 lines
576 B
TypeScript
20 lines
576 B
TypeScript
|
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,
|
||
|
};
|
||
|
};
|