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

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

{"version":3,"file":"i18nBundle.js","sourceRoot":"","sources":["../src/i18nBundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACpG,OAAO,aAAa,MAAM,yBAAyB,CAAC;AAEpD,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAAsB,CAAC;AAE1D,IAAI,mBAAqC,CAAC;AAS1C;;;GAGG;AACH,MAAM,UAAU;IAGf,YAAY,WAAmB;QAC9B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IAChC,CAAC;IAED;;;;;;OAMG;IACH,OAAO,CAAC,OAA0B,EAAE,GAAG,MAA8B;QACpE,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YAChC,OAAO,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC;SACjD;QAED,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE;YAC7B,OAAO,EAAE,CAAC;SACV;QAED,MAAM,MAAM,GAAG,iBAAiB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACnD,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACnC,sCAAsC;YACtC,OAAO,CAAC,IAAI,CAAC,OAAO,OAAO,CAAC,GAAG,8DAA8D,CAAC,CAAC;SAC/F;QACD,MAAM,WAAW,GAAG,MAAM,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;QAE/G,OAAO,aAAa,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC;CACD;AAED;;;;;GAKG;AACH,MAAM,iBAAiB,GAAG,CAAC,WAAmB,EAAc,EAAE;IAC7D,IAAI,mBAAmB,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;QACzC,OAAO,mBAAmB,CAAC,GAAG,CAAC,WAAW,CAAE,CAAC;KAC7C;IAED,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;IAC/C,mBAAmB,CAAC,GAAG,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IACjD,OAAO,UAAU,CAAC;AACnB,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,aAAa,GAAG,KAAK,EAAE,WAAmB,EAAuB,EAAE;IACxE,IAAI,mBAAmB,EAAE;QACxB,OAAO,mBAAmB,CAAC,WAAW,CAAC,CAAC;KACxC;IAED,MAAM,eAAe,CAAC,WAAW,CAAC,CAAC;IACnC,OAAO,iBAAiB,CAAC,WAAW,CAAC,CAAC;AACvC,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,8BAA8B,GAAG,CAAC,SAA2B,EAAQ,EAAE;IAC5E,mBAAmB,GAAG,SAAS,CAAC;AACjC,CAAC,CAAC;AAEF,eAAe,UAAU,CAAC;AAE1B,OAAO,EACN,kBAAkB,EAClB,aAAa,EACb,8BAA8B,GAC9B,CAAC","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"]}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy