All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.dist.locale.normalizeLocale.js.map Maven / Gradle / Ivy

{"version":3,"file":"normalizeLocale.js","sourceRoot":"","sources":["../../src/locale/normalizeLocale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEjE,MAAM,WAAW,GAAG,4MAA4M,CAAC;AACjO,MAAM,wBAAwB,GAAG,gCAAgC,CAAC;AAElE,wDAAwD;AACxD,MAAM,mBAAmB,GAAG;IAC3B,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;CACV,CAAC;AAEF;;;;GAIG;AACH,MAAM,eAAe,GAAG,CAAC,MAAc,EAAE,EAAE;IAC1C,IAAI,CAAC,CAAC;IAEN,IAAI,CAAC,MAAM,EAAE;QACZ,OAAO,cAAc,CAAC;KACtB;IAED,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAC,yBAAyB;QAC9G,IAAI,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QAClC,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QACnD,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QACrD,MAAM,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,S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]{3})*)((?:-[0-9A-WYZ](?:-[0-9A-Z]{2,8})+)*)(?:-(X(?:-[0-9A-Z]{1,8})+))?$/i;\nconst SAPSupportabilityLocales = /(?:^|-)(saptrc|sappsd)(?:-|$)/i;\n\n/* Map for old language names for a few ISO639 codes. */\nconst M_ISO639_NEW_TO_OLD = {\n\t\"he\": \"iw\",\n\t\"yi\": \"ji\",\n\t\"nb\": \"no\",\n\t\"sr\": \"sh\",\n};\n\n/**\n * Normalizes the given locale in BCP-47 syntax.\n * @param {string} locale locale to normalize\n * @returns {string} Normalized locale, \"undefined\" if the locale can't be normalized or the default locale, if no locale provided.\n */\nconst normalizeLocale = (locale: string) => {\n\tlet m;\n\n\tif (!locale) {\n\t\treturn DEFAULT_LOCALE;\n\t}\n\n\tif (typeof locale === \"string\" && (m = localeRegEX.exec(locale.replace(/_/g, \"-\")))) {/* eslint-disable-line */\n\t\tlet language = m[1].toLowerCase();\n\t\tlet region = m[3] ? m[3].toUpperCase() : undefined;\n\t\tconst script = m[2] ? m[2].toLowerCase() : undefined;\n\t\tconst variants = m[4] ? m[4].slice(1) : undefined;\n\t\tconst isPrivate = m[6];\n\n\t\tlanguage = M_ISO639_NEW_TO_OLD[language as keyof typeof M_ISO639_NEW_TO_OLD] || language;\n\n\t\t// recognize and convert special SAP supportability locales (overwrites m[]!)\n\t\tif ((isPrivate && (m = SAPSupportabilityLocales.exec(isPrivate))) /* eslint-disable-line */ ||\n\t\t\t(variants && (m = SAPSupportabilityLocales.exec(variants)))) {/* eslint-disable-line */\n\t\t\treturn `en_US_${m[1].toLowerCase()}`; // for now enforce en_US (agreed with SAP SLS)\n\t\t}\n\n\t\t// Chinese: when no region but a script is specified, use default region for each script\n\t\tif (language === \"zh\" && !region) {\n\t\t\tif (script === \"hans\") {\n\t\t\t\tregion = \"CN\";\n\t\t\t} else if (script === \"hant\") {\n\t\t\t\tregion = \"TW\";\n\t\t\t}\n\t\t}\n\n\t\treturn language + (region ? \"_\" + region + (variants ? \"_\" + variants.replace(\"-\", \"_\") : \"\") : \"\"); /* eslint-disable-line */\n\t}\n\n\treturn DEFAULT_LOCALE;\n};\n\nexport default normalizeLocale;\n"]}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy