"Fossies" - the Fresh Open Source Software Archive 
Member "jitsi-meet-7542/react/features/base/i18n/customNavigatorDetector.ts" (21 Sep 2023, 1591 Bytes) of package /linux/misc/jitsi-meet-7542.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1
2 declare let navigator: any;
3
4 /**
5 * Custom language detection, just returns the config property if any.
6 */
7 export default {
8 /**
9 * Does not support caching.
10 *
11 * @returns {void}
12 */
13 cacheUserLanguage: Function.prototype,
14
15 /**
16 * Looks the language up in the config.
17 *
18 * @returns {string} The default language if any.
19 */
20 lookup() {
21 let found = [];
22
23 if (typeof navigator !== 'undefined') {
24 if (navigator.languages) {
25 // chrome only; not an array, so can't use .push.apply instead of iterating
26 for (let i = 0; i < navigator.languages.length; i++) {
27 found.push(navigator.languages[i]);
28 }
29 }
30 if (navigator.userLanguage) {
31 found.push(navigator.userLanguage);
32 }
33 if (navigator.language) {
34 found.push(navigator.language);
35 }
36 }
37
38 found = found.map<string>(normalizeLanguage);
39
40 return found.length > 0 ? found : undefined;
41 },
42
43 /**
44 * Name of the language detector.
45 */
46 name: 'customNavigatorDetector'
47 };
48
49 /**
50 * Normalize language format.
51 *
52 * (en-US => enUS)
53 * (en-gb => enGB)
54 * (es-es => es).
55 *
56 * @param {string} language - Language.
57 * @returns {string} The normalized language.
58 */
59 function normalizeLanguage(language: string) {
60 const [ lang, variant ] = language.replace('_', '-').split('-');
61
62 if (!variant || lang === variant) {
63 return lang;
64 }
65
66 return lang + variant.toUpperCase();
67 }