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,"file":"i18n.js","sourceRoot":"","sources":["../../src/asset-registries/i18n.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,eAAe,MAAM,8BAA8B,CAAC;AAC3D,OAAO,kBAAkB,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAKhE,8DAA8D;AAC9D,MAAM,YAAY,GAAG,IAAI,GAAG,EAAE,CAAC;AAC/B,MAAM,cAAc,GAAG,IAAI,GAAG,EAAE,CAAC;AAEjC,MAAM,UAAU,GAAG,IAAI,GAAG,EAA2B,CAAC;AACtD,MAAM,cAAc,GAAG,IAAI,GAAG,EAA6B,CAAC;AAC5D,MAAM,OAAO,GAAG,IAAI,GAAG,EAAsB,CAAC;AAE9C;;;;;;;GAOG;AACH,MAAM,kBAAkB,GAAG,CAAC,WAAmB,EAAE,QAAgB,EAAE,MAAkB,EAAE,EAAE;IACxF,yBAAyB;IACzB,MAAM,SAAS,GAAG,GAAG,WAAW,IAAI,QAAQ,EAAE,CAAC;IAC/C,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;AAChC,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,WAAmB,EAAE,IAAqB,EAAE,EAAE;IACzE,UAAU,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;AACnC,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,CAAC,WAAmB,EAAE,EAAE;IACjD,OAAO,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AACpC,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG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C;YAC9B,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,yBAAyB;SACnD;KACD;AACF,CAAC,CAAC;AAEF,8GAA8G;AAC9G,oBAAoB,CAAC,CAAC,IAAY,CAAC,yBAAyB,EAAE,EAAE;IAC/D,MAAM,WAAW,GAAG,CAAC,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;IAC3C,OAAO,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC;AACtD,CAAC,CAAC,CAAC;AAEH,OAAO,EACN,kBAAkB,EAClB,eAAe,EACf,iBAAiB,GACjB,CAAC","sourcesContent":["import getLocale from \"../locale/getLocale.js\";\nimport { attachLanguageChange } from \"../locale/languageChange.js\";\nimport normalizeLocale from \"../locale/normalizeLocale.js\";\nimport nextFallbackLocale from \"../locale/nextFallbackLocale.js\";\nimport { DEFAULT_LANGUAGE } from \"../generated/AssetParameters.js\";\nimport { getFetchDefaultLanguage } from \"../config/Language.js\";\n\ntype I18nLoader = (localeId: string) => Promise;\ntype I18nData = Record;\n\n// contains package names for which the warning has been shown\nconst warningShown = new Set();\nconst reportedErrors = new Set();\n\nconst bundleData = new Map();\nconst bundlePromises = new Map>();\nconst loaders = new Map();\n\n/**\n * Registers i18n loader function for given package and locale.\n *\n * @public\n * @param {string} packageName for which package this loader can fetch data\n * @param {string} localeId locale that this loader can handle\n * @param {function} loader async function that will be passed a localeId and should return a JSON object\n */\nconst registerI18nLoader = (packageName: string, localeId: string, loader: I18nLoader) => {\n\t// register loader by key\n\tconst bundleKey = `${packageName}/${localeId}`;\n\tloaders.set(bundleKey, loader);\n};\n\nconst _setI18nBundleData = (packageName: string, data: I18nData | null) => {\n\tbundleData.set(packageName, data);\n};\n\nconst getI18nBundleData = (packageName: string) => {\n\treturn bundleData.get(packageName);\n};\n\nconst _hasLoader = (packageName: string, localeId: string) => {\n\tconst bundleKey = `${packageName}/${localeId}`;\n\treturn loaders.has(bundleKey);\n};\n\n// load bundle over the network once\nconst _loadMessageBundleOnce = (packageName: string, localeId: string) => {\n\tconst bundleKey = `${packageName}/${localeId}`;\n\tconst loadMessageBundle = loaders.get(bundleKey);\n\n\tif (loadMessageBundle && !bundlePromises.get(bundleKey)) {\n\t\tbundlePromises.set(bundleKey, loadMessageBundle(localeId));\n\t}\n\n\treturn bundlePromises.get(bundleKey)!; // Investigate if i18n loader exists and this won't return undefined.\n};\n\nconst _showAssetsWarningOnce = (packageName: string) => {\n\tif (!warningShown.has(packageName)) {\n\t\tconsole.warn(`[${packageName}]: Message bundle assets are not configured. Falling back to English texts.`, /* eslint-disable-line */\n\t\t\t` Add \\`import \"${packageName}/dist/Assets.js\"\\` in your bundle and make sure your build tool supports dynamic imports and JSON imports. See section \"Assets\" in the documentation for more information.`); /* eslint-disable-line */\n\t\twarningShown.add(packageName);\n\t}\n};\n\nconst useFallbackBundle = (packageName: string, localeId: string) => {\n\treturn localeId !== DEFAULT_LANGUAGE && !_hasLoader(packageName, localeId);\n};\n\n/**\n * This method preforms the asynchronous task of fetching the actual text resources. It will fetch\n * each text resource over the network once (even for multiple calls to the same method).\n * It should be fully finished before the i18nBundle class is created in the webcomponents.\n * This method uses the bundle URLs that are populated by the `registerI18nBundle` method.\n * To simplify the usage, the synchronization of both methods happens internally for the same `bundleId`\n * @param {packageName} packageName the NPM package name\n * @public\n */\nconst fetchI18nBundle = async (packageName: string) => {\n\tconst language = getLocale().getLanguage();\n\tconst region = getLocale().getRegion();\n\tconst variant = getLocale().getVariant();\n\tlet localeId = language + (region ? `-${region}` : ``) + (variant ? `-${variant}` : ``);\n\n\tif (useFallbackBundle(packageName, localeId)) {\n\t\tlocaleId = normalizeLocale(localeId);\n\n\t\twhile (useFallbackBundle(packageName, localeId)) {\n\t\t\tlocaleId = nextFallbackLocale(localeId);\n\t\t}\n\t}\n\n\t// use default language unless configured to always fetch it from the network\n\tconst fetchDefaultLanguage = getFetchDefaultLanguage();\n\tif (localeId === DEFAULT_LANGUAGE && !fetchDefaultLanguage) {\n\t\t_setI18nBundleData(packageName, null); // reset for the default language (if data was set for a previous language)\n\t\treturn;\n\t}\n\n\tif (!_hasLoader(packageName, localeId)) {\n\t\t_showAssetsWarningOnce(packageName);\n\t\treturn;\n\t}\n\n\ttry {\n\t\tconst data = await _loadMessageBundleOnce(packageName, localeId);\n\t\t_setI18nBundleData(packageName, data);\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\n// When the language changes dynamically (the user calls setLanguage), re-fetch all previously fetched bundles\nattachLanguageChange((lang: string /* eslint-disable-line */) => {\n\tconst allPackages = [...bundleData.keys()];\n\treturn Promise.all(allPackages.map(fetchI18nBundle));\n});\n\nexport {\n\tregisterI18nLoader,\n\tfetchI18nBundle,\n\tgetI18nBundleData,\n};\n"]}