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

package.dist.prod.i18nBundle.js.map Maven / Gradle / Ivy

{
  "version": 3,
  "sources": ["../../src/i18nBundle.ts"],
  "sourcesContent": ["import { registerI18nLoader, fetchI18nBundle, getI18nBundleData } from \"./asset-registries/i18n.js\";\nimport formatMessage from \"./util/formatMessage.js\";\n\nconst I18nBundleInstances = new Map();\n\nlet customGetI18nBundle: I18nBundleGetter;\n\ntype I18nText = {\n\tkey: string,\n\tdefaultText: string,\n};\n\ntype I18nBundleGetter = (packageName: string) => Promise;\n\n/**\n * @class\n * @public\n */\nclass I18nBundle {\n\tpackageName: string;\n\n\tconstructor(packageName: string) {\n\t\tthis.packageName = packageName;\n\t}\n\n\t/**\n\t * Returns a text in the currently loaded language\n\t *\n\t * @public\n\t * @param textObj key/defaultText pair or just the key\n\t * @param params Values for the placeholders\n\t */\n\tgetText(textObj: I18nText | string, ...params: Array): string {\n\t\tif (typeof textObj === \"string\") {\n\t\t\ttextObj = { key: textObj, defaultText: textObj };\n\t\t}\n\n\t\tif (!textObj || !textObj.key) {\n\t\t\treturn \"\";\n\t\t}\n\n\t\tconst bundle = getI18nBundleData(this.packageName);\n\t\tif (bundle && !bundle[textObj.key]) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.warn(`Key ${textObj.key} not found in the i18n bundle, the default text will be used`);\n\t\t}\n\t\tconst messageText = bundle && bundle[textObj.key] ? bundle[textObj.key] : (textObj.defaultText || textObj.key);\n\n\t\treturn formatMessage(messageText, params);\n\t}\n}\n\n/**\n * Returns the I18nBundle instance for the given package synchronously.\n *\n * @public\n * @param packageName\n */\nconst getI18nBundleSync = (packageName: string): I18nBundle => {\n\tif (I18nBundleInstances.has(packageName)) {\n\t\treturn I18nBundleInstances.get(packageName)!;\n\t}\n\n\tconst i18nBundle = new I18nBundle(packageName);\n\tI18nBundleInstances.set(packageName, i18nBundle);\n\treturn i18nBundle;\n};\n\n/**\n * Fetches and returns the I18nBundle instance for the given package.\n *\n * @public\n * @param packageName\n */\nconst getI18nBundle = async (packageName: string): Promise => {\n\tif (customGetI18nBundle) {\n\t\treturn customGetI18nBundle(packageName);\n\t}\n\n\tawait fetchI18nBundle(packageName);\n\treturn getI18nBundleSync(packageName);\n};\n\n/**\n * Allows developers to provide a custom getI18nBundle implementation\n * If this function is called, the custom implementation will be used for all components and will completely\n * replace the default implementation.\n *\n * @public\n * @param customGet the function to use instead of the standard getI18nBundle implementation\n */\nconst registerCustomI18nBundleGetter = (customGet: I18nBundleGetter): void => {\n\tcustomGetI18nBundle = customGet;\n};\n\nexport default I18nBundle;\n\nexport {\n\tregisterI18nLoader,\n\tgetI18nBundle,\n\tregisterCustomI18nBundleGetter,\n};\n\nexport type {\n\tI18nText,\n};\n"],
  "mappings": "aAAA,OAAS,sBAAAA,EAAoB,mBAAAC,EAAiB,qBAAAC,MAAyB,6BACvE,OAAOC,MAAmB,0BAE1B,MAAMC,EAAsB,IAAI,IAEhC,IAAIC,EAaJ,MAAMC,CAAW,CAGhB,YAAYC,EAAqB,CAChC,KAAK,YAAcA,CACpB,CASA,QAAQC,KAA+BC,EAAwC,CAK9E,GAJI,OAAOD,GAAY,WACtBA,EAAU,CAAE,IAAKA,EAAS,YAAaA,CAAQ,GAG5C,CAACA,GAAW,CAACA,EAAQ,IACxB,MAAO,GAGR,MAAME,EAASR,EAAkB,KAAK,WAAW,EAC7CQ,GAAU,CAACA,EAAOF,EAAQ,GAAG,GAEhC,QAAQ,KAAK,OAAOA,EAAQ,GAAG,8DAA8D,EAE9F,MAAMG,EAAcD,GAAUA,EAAOF,EAAQ,GAAG,EAAIE,EAAOF,EAAQ,GAAG,EAAKA,EAAQ,aAAeA,EAAQ,IAE1G,OAAOL,EAAcQ,EAAaF,CAAM,CACzC,CACD,CAQA,MAAMG,EAAqBL,GAAoC,CAC9D,GAAIH,EAAoB,IAAIG,CAAW,EACtC,OAAOH,EAAoB,IAAIG,CAAW,EAG3C,MAAMM,EAAa,IAAIP,EAAWC,CAAW,EAC7C,OAAAH,EAAoB,IAAIG,EAAaM,CAAU,EACxCA,CACR,EAQMC,EAAgB,MAAOP,GACxBF,EACIA,EAAoBE,CAAW,GAGvC,MAAMN,EAAgBM,CAAW,EAC1BK,EAAkBL,CAAW,GAW/BQ,EAAkCC,GAAsC,CAC7EX,EAAsBW,CACvB,EAEA,eAAeV,EAEf,OACCN,KAAA,mBACAc,KAAA,cACAC,KAAA",
  "names": ["registerI18nLoader", "fetchI18nBundle", "getI18nBundleData", "formatMessage", "I18nBundleInstances", "customGetI18nBundle", "I18nBundle", "packageName", "textObj", "params", "bundle", "messageText", "getI18nBundleSync", "i18nBundle", "getI18nBundle", "registerCustomI18nBundleGetter", "customGet"]
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy