"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-7313/react/features/base/i18n/languageDetector.native.ts" (2 Jun 2023, 1013 Bytes) of package /linux/misc/jitsi-meet-7313.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 import { NativeModules } from 'react-native';
    2 
    3 import LANGUAGES_RESOURCES from '../../../../lang/languages.json';
    4 
    5 const LANGUAGES = Object.keys(LANGUAGES_RESOURCES);
    6 
    7 /**
    8  * The singleton language detector for React Native which uses the system-wide
    9  * locale.
   10  */
   11 export default {
   12     /**
   13      * Does not support caching.
   14      *
   15      * @returns {void}
   16      */
   17     cacheUserLanguage: Function.prototype,
   18 
   19     detect() {
   20         const { LocaleDetector } = NativeModules;
   21         const parts = LocaleDetector.locale.replace(/_/, '-').split('-');
   22         const [ lang, regionOrScript, region ] = parts;
   23         let locale;
   24 
   25         if (parts.length >= 3) {
   26             locale = `${lang}${region}`;
   27         } else if (parts.length === 2) {
   28             locale = `${lang}${regionOrScript}`;
   29         } else {
   30             locale = lang;
   31         }
   32 
   33         if (LANGUAGES.includes(locale)) {
   34             return locale;
   35         }
   36 
   37         return lang;
   38     },
   39 
   40     init: Function.prototype,
   41 
   42     type: 'languageDetector'
   43 };