mirror of
https://github.com/imputnet/cobalt.git
synced 2024-12-28 02:26:10 +00:00
web/settings: add function for getting browser language
prep for migrating youtubeDubBrowserLang
This commit is contained in:
parent
7a50c89728
commit
7c9a824a69
|
@ -78,6 +78,8 @@ export const youtubeLanguages = [
|
|||
"zu"
|
||||
] as const;
|
||||
|
||||
export type YoutubeLang = typeof youtubeLanguages[number];
|
||||
|
||||
export const namedYoutubeLanguages = () => {
|
||||
return youtubeLanguages.reduce((obj, lang) => {
|
||||
const intlName = new Intl.DisplayNames([lang], { type: 'language' }).of(lang);
|
||||
|
@ -91,5 +93,20 @@ export const namedYoutubeLanguages = () => {
|
|||
...obj,
|
||||
[lang]: name,
|
||||
};
|
||||
}, {}) as Record<typeof youtubeLanguages[number], string>;
|
||||
}, {}) as Record<YoutubeLang, string>;
|
||||
}
|
||||
|
||||
export const getBrowserLanguage = (): YoutubeLang => {
|
||||
if (typeof navigator === 'undefined')
|
||||
return "original";
|
||||
|
||||
const browserLanguage = navigator.language as YoutubeLang;
|
||||
if (youtubeLanguages.includes(browserLanguage))
|
||||
return browserLanguage;
|
||||
|
||||
const shortened = browserLanguage.split('-')[0] as YoutubeLang;
|
||||
if (youtubeLanguages.includes(shortened))
|
||||
return shortened;
|
||||
|
||||
return "original";
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue