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

package.dist.asset-registries.LocaleData.js.map Maven / Gradle / Ivy

{"version":3,"file":"LocaleData.js","sourceRoot":"","sources":["../../src/asset-registries/LocaleData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpF,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAMpD,MAAM,aAAa,GAAG,IAAI,GAAG,EAAoB,CAAC;AAClD,MAAM,OAAO,GAAG,IAAI,GAAG,EAA4B,CAAC;AACpD,MAAM,YAAY,GAAG,IAAI,GAAG,EAA6B,CAAC;AAC1D,MAAM,cAAc,GAAG,IAAI,GAAG,EAAU,CAAC;AACzC,IAAI,YAAY,GAAG,KAAK,CAAC;AAEzB,MAAM,mBAAmB,GAAG;IAC3B,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;CACV,CAAC;AAEF,MAAM,sBAAsB,GAAG,CAAC,QAAgB,EAAE,EAAE;IACnD,IAAI,YAAY,EAAE;QACjB,OAAO;KACP;IAED,OAAO,CAAC,IAAI,CAAC,kCAAkC,QAAQ,+FAA+F,CAAC,CAAC,CAAC,yBAAyB;IAElL,YAAY,GAAG,IAAI,CAAC;AACrB,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,QAAgB,EAAE,MAAc,EAAE,MAAc,EAAE,EAAE;IACvE,8CAA8C;IAC9C,QAAQ,GAAG,CAAC,QAAQ,IAAI,mBAAmB,CAAC,QAA4C,CAAC,CAAC,IAAI,QAAQ,CAAC;IACvG,2GAA2G;IAC3G,IAAI,QAAQ,KAAK,IAAI,EAAE;QACtB,QAAQ,GAAG,IAAI,CAAC;KAChB;IACD,8GAA8G;IAC9G,IAAI,QAAQ,KAAK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O;SACP;KACD;IAED,WAAW;IACX,IAAI;QACH,MAAM,WAAW,GAAG,MAAM,aAAa,CAAC,QAAQ,CAAC,CAAC;QAClD,aAAa,CAAC,QAAQ,EAAE,WAAuB,CAAC,CAAC;KACjD;IAAC,OAAO,KAAc,EAAE;QACxB,MAAM,CAAC,GAAG,KAAc,CAAC;QACzB,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE;YACnC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;YAC9B,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,yBAAyB;SACnD;KACD;AACF,CAAC,CAAC;AAEF,MAAM,wBAAwB,GAAG,CAAC,QAAgB,EAAE,MAAwB,EAAE,EAAE;IAC/E,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AAC/B,CAAC,CAAC;AAEF,8EAA8E;AAC9E,wBAAwB,CAAC,IAAI,EAAE,KAAK,IAAI,EAAE;IACzC,MAAM,WAAW,GAAG,MAAM,KAAK,CAAC,qEAAqE,CAAC,CAAC;IACvG,OAAO,WAAW,CAAC,IAAI,EAAuB,CAAC;AAChD,CAAC,CAAC,CAAC;AAEH,sEAAsE;AACtE,mCAAmC;AACnC,oBAAoB,CAAC,GAAG,EAAE;IACzB,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,OAAO,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,MAAM,CAAC,SAAS,EAAE,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;AAChF,CAAC,CAAC,CAAC;AAEH,OAAO,EACN,wBAAwB,EACxB,SAAS,EACT,aAAa,GACb,CAAC","sourcesContent":["import { attachLanguageChange } from \"../locale/languageChange.js\";\nimport getLocale from \"../locale/getLocale.js\";\nimport { DEFAULT_LOCALE, SUPPORTED_LOCALES } from \"../generated/AssetParameters.js\";\nimport { getFeature } from \"../FeaturesRegistry.js\";\nimport type OpenUI5Support from \"../features/OpenUI5Support.js\";\n\ntype LocaleDataLoader = (locale: string) => Promise;\ntype CLDRData = Record;\n\nconst localeDataMap = new Map();\nconst loaders = new Map();\nconst cldrPromises = new Map>();\nconst reportedErrors = new Set();\nlet warningShown = false;\n\nconst M_ISO639_OLD_TO_NEW = {\n\t\"iw\": \"he\",\n\t\"ji\": \"yi\",\n\t\"in\": \"id\",\n};\n\nconst _showAssetsWarningOnce = (localeId: string) => {\n\tif (warningShown) {\n\t\treturn;\n\t}\n\n\tconsole.warn(`[LocaleData] Supported locale \"${localeId}\" not configured, import the \"Assets.js\" module from the webcomponents package you are using.`); /* eslint-disable-line */\n\n\twarningShown = true;\n};\n\nconst calcLocale = (language: string, region: string, script: string) => {\n\t// normalize language and handle special cases\n\tlanguage = (language && M_ISO639_OLD_TO_NEW[language as keyof typeof M_ISO639_OLD_TO_NEW]) || language;\n\t// Special case 1: in an SAP context, the inclusive language code \"no\" always means Norwegian Bokmal (\"nb\")\n\tif (language === \"no\") {\n\t\tlanguage = \"nb\";\n\t}\n\t// Special case 2: for Chinese, derive a default region from the script (this behavior is inherited from Java)\n\tif (language === \"zh\" && !region) {\n\t\tif (script === \"Hans\") {\n\t\t\tregion = \"CN\";\n\t\t} else if (script === \"Hant\") {\n\t\t\tregion = \"TW\";\n\t\t}\n\t}\n\n\t// Special case 3: for Serbian, there are cyrillic and latin scripts, \"sh\" and \"sr-latn\" map to \"latin\", \"sr\" maps to cyrillic.\n\tif (language === \"sh\" || (language === \"sr\" && script === \"Latn\")) {\n\t\tlanguage = \"sr\";\n\t\tregion = \"Latn\";\n\t}\n\n\t// try language + region\n\tlet localeId = `${language}_${region}`;\n\tif (SUPPORTED_LOCALES.includes(localeId)) {\n\t\tif (loaders.has(localeId)) {\n\t\t\t// supported and has loader\n\t\t\treturn localeId;\n\t\t}\n\n\t\t// supported, no loader - fallback to default and warn\n\t\t_showAssetsWarningOnce(localeId);\n\t\treturn DEFAULT_LOCALE;\n\t}\n\n\t// not supported, try language only\n\tlocaleId = language;\n\tif (SUPPORTED_LOCALES.includes(localeId)) {\n\t\tif (loaders.has(localeId)) {\n\t\t\t// supported and has loader\n\t\t\treturn localeId;\n\t\t}\n\n\t\t// supported, no loader - fallback to default and warn\n\t\t_showAssetsWarningOnce(localeId);\n\t\treturn DEFAULT_LOCALE;\n\t}\n\n\t// not supported - fallback to default locale\n\treturn DEFAULT_LOCALE;\n};\n\n// internal set data\nconst setLocaleData = (localeId: string, content: CLDRData) => {\n\tlocaleDataMap.set(localeId, content);\n};\n\n// external getSync\nconst getLocaleData = (localeId: string) => {\n\t// if there is no loader, the default fallback was fetched and a warning was given - use default locale instead\n\tif (!loaders.has(localeId)) {\n\t\tlocaleId = DEFAULT_LOCALE;\n\t}\n\n\tconst content = localeDataMap.get(localeId);\n\tif (!content) {\n\t\tthrow new Error(`CLDR data for locale ${localeId} is not loaded!`);\n\t}\n\n\treturn content;\n};\n\n// load bundle over the network once\nconst _loadCldrOnce = (localeId: string) => {\n\tif (!cldrPromises.get(localeId)) {\n\t\tconst loadCldr = loaders.get(localeId);\n\n\t\tif (!loadCldr) {\n\t\t\tthrow new Error(`CLDR data for locale ${localeId} is not loaded!`);\n\t\t}\n\n\t\tcldrPromises.set(localeId, loadCldr(localeId));\n\t}\n\n\treturn cldrPromises.get(localeId);\n};\n\n// external getAsync\nconst fetchCldr = async (language: string, region: string, script: string) => {\n\tconst localeId = calcLocale(language, region, script);\n\n\t// reuse OpenUI5 CLDR if present\n\tconst openUI5Support = getFeature(\"OpenUI5Support\");\n\tif (openUI5Support) {\n\t\tconst cldrContent = openUI5Support.getLocaleDataObject();\n\t\tif (cldrContent) {\n\t\t\t// only if openui5 actually returned valid content\n\t\t\tsetLocaleData(localeId, cldrContent);\n\t\t\treturn;\n\t\t}\n\t}\n\n\t// fetch it\n\ttry {\n\t\tconst cldrContent = await _loadCldrOnce(localeId);\n\t\tsetLocaleData(localeId, cldrContent as CLDRData);\n\t} catch (error: unknown) {\n\t\tconst e = error as Error;\n\t\tif (!reportedErrors.has(e.message)) {\n\t\t\treportedErrors.add(e.message);\n\t\t\tconsole.error(e.message); /* eslint-disable-line */\n\t\t}\n\t}\n};\n\nconst registerLocaleDataLoader = (localeId: string, loader: LocaleDataLoader) => {\n\tloaders.set(localeId, loader);\n};\n\n// register default loader for \"en\" from ui5 CDN (dev workflow without assets)\nregisterLocaleDataLoader(\"en\", async () => {\n\tconst cldrContent = await fetch(`https://sdk.openui5.org/1.120.17/resources/sap/ui/core/cldr/en.json`);\n\treturn cldrContent.json() as Promise;\n});\n\n// When the language changes dynamically (the user calls setLanguage),\n// re-fetch the required CDRD data.\nattachLanguageChange(() => {\n\tconst locale = getLocale();\n\treturn fetchCldr(locale.getLanguage(), locale.getRegion(), locale.getScript());\n});\n\nexport {\n\tregisterLocaleDataLoader,\n\tfetchCldr,\n\tgetLocaleData,\n};\n\nexport type {\n\tCLDRData,\n};\n"]}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy