Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
{
"version": 3,
"sources": ["../../../src/asset-registries/LocaleData.ts"],
"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"],
"mappings": "aAAA,OAAS,wBAAAA,MAA4B,8BACrC,OAAOC,MAAe,yBACtB,OAAS,kBAAAC,EAAgB,qBAAAC,MAAyB,kCAClD,OAAS,cAAAC,MAAkB,yBAM3B,MAAMC,EAAgB,IAAI,IACpBC,EAAU,IAAI,IACdC,EAAe,IAAI,IACnBC,EAAiB,IAAI,IAC3B,IAAIC,EAAe,GAEnB,MAAMC,EAAsB,CAC3B,GAAM,KACN,GAAM,KACN,GAAM,IACP,EAEMC,EAA0BC,GAAqB,CAChDH,IAIJ,QAAQ,KAAK,kCAAkCG,CAAQ,+F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zE,GAAImB,EAAgB,CACnB,MAAMC,EAAcD,EAAe,oBAAoB,EACvD,GAAIC,EAAa,CAEhBP,EAAcL,EAAUY,CAAW,EACnC,MACD,CACD,CAGA,GAAI,CACH,MAAMA,EAAc,MAAMJ,EAAcR,CAAQ,EAChDK,EAAcL,EAAUY,CAAuB,CAChD,OAASC,EAAgB,CACxB,MAAMC,EAAID,EACLjB,EAAe,IAAIkB,EAAE,OAAO,IAChClB,EAAe,IAAIkB,EAAE,OAAO,EAC5B,QAAQ,MAAMA,EAAE,OAAO,EAEzB,CACD,EAEMC,EAA2B,CAACf,EAAkBgB,IAA6B,CAChFtB,EAAQ,IAAIM,EAAUgB,CAAM,CAC7B,EAGAD,EAAyB,KAAM,UACV,MAAM,MAAM,qEAAqE,GAClF,KAAK,CACxB,EAID3B,EAAqB,IAAM,CAC1B,MAAM6B,EAAS5B,EAAU,EACzB,OAAOqB,EAAUO,EAAO,YAAY,EAAGA,EAAO,UAAU,EAAGA,EAAO,UAAU,CAAC,CAC9E,CAAC,EAED,OACCF,KAAA,yBACAL,KAAA,UACAH,KAAA",
"names": ["attachLanguageChange", "getLocale", "DEFAULT_LOCALE", "SUPPORTED_LOCALES", "getFeature", "localeDataMap", "loaders", "cldrPromises", "reportedErrors", "warningShown", "M_ISO639_OLD_TO_NEW", "_showAssetsWarningOnce", "localeId", "calcLocale", "language", "region", "script", "setLocaleData", "content", "getLocaleData", "_loadCldrOnce", "loadCldr", "fetchCldr", "openUI5Support", "cldrContent", "error", "e", "registerLocaleDataLoader", "loader", "locale"]
}