@dcloudio/vue-cli-plugin-uni 2.0.0 → 2.0.1-32920211122002
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commands/build.js +64 -33
- package/commands/serve.js +12 -17
- package/generator.js +6 -2
- package/index.js +5 -3
- package/lib/chain-webpack.js +8 -1
- package/lib/check-update.js +56 -0
- package/lib/commands/custom.js +7 -4
- package/lib/commands/invoke.js +5 -4
- package/lib/configure-webpack.js +35 -5
- package/lib/copy-webpack-options.js +60 -20
- package/lib/env.js +99 -51
- package/lib/error-reporting.js +9 -3
- package/lib/mp/index.js +31 -16
- package/lib/options.js +6 -3
- package/lib/util.js +5 -6
- package/package.json +3 -3
- package/packages/@vue/component-compiler-utils/MODIFY.md +5 -0
- package/packages/@vue/component-compiler-utils/dist/compileStyle.js +11 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/API.md +873 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/CHANGELOG.md +466 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/LICENSE-MIT +22 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/README.md +49 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/index.js +26 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/parser.js +1088 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/processor.js +185 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/attribute.js +468 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/className.js +67 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/combinator.js +35 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/comment.js +35 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/constructors.js +91 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/container.js +392 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/guards.js +54 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/id.js +39 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/index.js +39 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/namespace.js +98 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/nesting.js +36 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/node.js +216 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/pseudo.js +40 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/root.js +60 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/selector.js +35 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/string.js +35 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/tag.js +35 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/types.js +15 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/universal.js +36 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/sortAscending.js +10 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/tokenTypes.js +39 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/tokenize.js +271 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/util/ensureObject.js +20 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/util/getProp.js +22 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/util/index.js +41 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/util/stripComments.js +21 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/util/unesc.js +18 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/package.json +76 -0
- package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/postcss-selector-parser.d.ts +499 -0
- package/packages/@vue/devtools-api/lib/cjs/api/api.d.ts +90 -0
- package/packages/@vue/devtools-api/lib/cjs/api/api.js +2 -0
- package/packages/@vue/devtools-api/lib/cjs/api/app.d.ts +1 -0
- package/packages/@vue/devtools-api/lib/cjs/api/app.js +2 -0
- package/packages/@vue/devtools-api/lib/cjs/api/component.d.ts +76 -0
- package/packages/@vue/devtools-api/lib/cjs/api/component.js +2 -0
- package/packages/@vue/devtools-api/lib/cjs/api/context.d.ts +5 -0
- package/packages/@vue/devtools-api/lib/cjs/api/context.js +2 -0
- package/packages/@vue/devtools-api/lib/cjs/api/hooks.d.ts +169 -0
- package/packages/@vue/devtools-api/lib/cjs/api/hooks.js +2 -0
- package/packages/@vue/devtools-api/lib/cjs/api/index.d.ts +6 -0
- package/packages/@vue/devtools-api/lib/cjs/api/index.js +18 -0
- package/packages/@vue/devtools-api/lib/cjs/api/util.d.ts +4 -0
- package/packages/@vue/devtools-api/lib/cjs/api/util.js +2 -0
- package/packages/@vue/devtools-api/lib/cjs/const.d.ts +1 -0
- package/packages/@vue/devtools-api/lib/cjs/const.js +4 -0
- package/packages/@vue/devtools-api/lib/cjs/env.d.ts +10 -0
- package/packages/@vue/devtools-api/lib/cjs/env.js +16 -0
- package/packages/@vue/devtools-api/lib/cjs/index.d.ts +14 -0
- package/packages/@vue/devtools-api/lib/cjs/index.js +31 -0
- package/packages/@vue/devtools-api/lib/esm/api/api.js +0 -0
- package/packages/@vue/devtools-api/lib/esm/api/app.js +0 -0
- package/packages/@vue/devtools-api/lib/esm/api/component.js +0 -0
- package/packages/@vue/devtools-api/lib/esm/api/context.js +0 -0
- package/packages/@vue/devtools-api/lib/esm/api/hooks.js +0 -0
- package/packages/@vue/devtools-api/lib/esm/api/index.js +6 -0
- package/packages/@vue/devtools-api/lib/esm/api/util.js +0 -0
- package/packages/@vue/devtools-api/lib/esm/const.js +1 -0
- package/packages/@vue/devtools-api/lib/esm/env.js +11 -0
- package/packages/@vue/devtools-api/lib/esm/index.js +17 -0
- package/packages/@vue/devtools-api/package.json +38 -0
- package/packages/app-vue-style-loader/lib/addStylesClient.js +1 -1
- package/packages/h5-vue-style-loader/lib/addStylesClient.js +1 -1
- package/packages/mp-vue/dist/mp.runtime.esm.js +3 -2
- package/packages/mp-vue/package.json +1 -0
- package/packages/uni-app/LICENSE +202 -0
- package/packages/uni-app/dist/uni-app.cjs.js +165 -0
- package/packages/uni-app/dist/uni-app.d.ts +61 -0
- package/packages/uni-app/dist/uni-app.es.js +108 -0
- package/packages/uni-app/package.json +22 -0
- package/packages/uni-cloud/dist/index.js +1 -1
- package/packages/uni-stat/dist/uni-stat.cjs.js +961 -0
- package/packages/uni-stat/dist/uni-stat.es.js +959 -0
- package/packages/uni-stat/lib/uni.plugin.js +68 -0
- package/packages/uni-stat/package.json +25 -0
- package/packages/vue3/node_modules/.yarn-integrity +27 -0
- package/packages/vue3/node_modules/@intlify/core-base/LICENSE +20 -0
- package/packages/vue3/node_modules/@intlify/core-base/README.md +7 -0
- package/packages/vue3/node_modules/@intlify/core-base/dist/core-base.cjs.js +989 -0
- package/packages/vue3/node_modules/@intlify/core-base/dist/core-base.cjs.prod.js +735 -0
- package/packages/vue3/node_modules/@intlify/core-base/dist/core-base.d.ts +576 -0
- package/packages/vue3/node_modules/@intlify/core-base/dist/core-base.esm-browser.js +2771 -0
- package/packages/vue3/node_modules/@intlify/core-base/dist/core-base.esm-browser.prod.js +6 -0
- package/packages/vue3/node_modules/@intlify/core-base/dist/core-base.esm-bundler.js +965 -0
- package/packages/vue3/node_modules/@intlify/core-base/dist/core-base.global.js +2814 -0
- package/packages/vue3/node_modules/@intlify/core-base/dist/core-base.global.prod.js +6 -0
- package/packages/vue3/node_modules/@intlify/core-base/index.js +7 -0
- package/packages/vue3/node_modules/@intlify/core-base/package.json +59 -0
- package/packages/vue3/node_modules/@intlify/devtools-if/LICENSE +20 -0
- package/packages/vue3/node_modules/@intlify/devtools-if/README.md +13 -0
- package/packages/vue3/node_modules/@intlify/devtools-if/dist/devtools-if.cjs.js +15 -0
- package/packages/vue3/node_modules/@intlify/devtools-if/dist/devtools-if.cjs.prod.js +15 -0
- package/packages/vue3/node_modules/@intlify/devtools-if/dist/devtools-if.d.ts +43 -0
- package/packages/vue3/node_modules/@intlify/devtools-if/dist/devtools-if.esm-bundler.js +11 -0
- package/packages/vue3/node_modules/@intlify/devtools-if/index.js +7 -0
- package/packages/vue3/node_modules/@intlify/devtools-if/package.json +49 -0
- package/packages/vue3/node_modules/@intlify/message-compiler/LICENSE +20 -0
- package/packages/vue3/node_modules/@intlify/message-compiler/README.md +7 -0
- package/packages/vue3/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.js +1400 -0
- package/packages/vue3/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.prod.js +1395 -0
- package/packages/vue3/node_modules/@intlify/message-compiler/dist/message-compiler.d.ts +197 -0
- package/packages/vue3/node_modules/@intlify/message-compiler/dist/message-compiler.esm-browser.js +1348 -0
- package/packages/vue3/node_modules/@intlify/message-compiler/dist/message-compiler.esm-browser.prod.js +6 -0
- package/packages/vue3/node_modules/@intlify/message-compiler/dist/message-compiler.esm-bundler.js +1329 -0
- package/packages/vue3/node_modules/@intlify/message-compiler/dist/message-compiler.global.js +1365 -0
- package/packages/vue3/node_modules/@intlify/message-compiler/dist/message-compiler.global.prod.js +6 -0
- package/packages/vue3/node_modules/@intlify/message-compiler/index.js +7 -0
- package/packages/vue3/node_modules/@intlify/message-compiler/package.json +56 -0
- package/packages/vue3/node_modules/@intlify/message-resolver/LICENSE +20 -0
- package/packages/vue3/node_modules/@intlify/message-resolver/README.md +7 -0
- package/packages/vue3/node_modules/@intlify/message-resolver/dist/message-resolver.cjs.js +302 -0
- package/packages/vue3/node_modules/@intlify/message-resolver/dist/message-resolver.cjs.prod.js +302 -0
- package/packages/vue3/node_modules/@intlify/message-resolver/dist/message-resolver.d.ts +21 -0
- package/packages/vue3/node_modules/@intlify/message-resolver/dist/message-resolver.esm-bundler.js +297 -0
- package/packages/vue3/node_modules/@intlify/message-resolver/index.js +7 -0
- package/packages/vue3/node_modules/@intlify/message-resolver/package.json +46 -0
- package/packages/vue3/node_modules/@intlify/runtime/LICENSE +20 -0
- package/packages/vue3/node_modules/@intlify/runtime/README.md +7 -0
- package/packages/vue3/node_modules/@intlify/runtime/dist/runtime.cjs.js +116 -0
- package/packages/vue3/node_modules/@intlify/runtime/dist/runtime.cjs.prod.js +116 -0
- package/packages/vue3/node_modules/@intlify/runtime/dist/runtime.d.ts +95 -0
- package/packages/vue3/node_modules/@intlify/runtime/dist/runtime.esm-bundler.js +111 -0
- package/packages/vue3/node_modules/@intlify/runtime/index.js +7 -0
- package/packages/vue3/node_modules/@intlify/runtime/package.json +51 -0
- package/packages/vue3/node_modules/@intlify/shared/LICENSE +20 -0
- package/packages/vue3/node_modules/@intlify/shared/README.md +18 -0
- package/packages/vue3/node_modules/@intlify/shared/dist/shared.cjs.js +222 -0
- package/packages/vue3/node_modules/@intlify/shared/dist/shared.cjs.prod.js +209 -0
- package/packages/vue3/node_modules/@intlify/shared/dist/shared.d.ts +145 -0
- package/packages/vue3/node_modules/@intlify/shared/dist/shared.esm-bundler.js +192 -0
- package/packages/vue3/node_modules/@intlify/shared/index.js +7 -0
- package/packages/vue3/node_modules/@intlify/shared/package.json +46 -0
- package/packages/vue3/node_modules/@intlify/vue-devtools/LICENSE +20 -0
- package/packages/vue3/node_modules/@intlify/vue-devtools/README.md +7 -0
- package/packages/vue3/node_modules/@intlify/vue-devtools/dist/vue-devtools.cjs.js +24 -0
- package/packages/vue3/node_modules/@intlify/vue-devtools/dist/vue-devtools.cjs.prod.js +24 -0
- package/packages/vue3/node_modules/@intlify/vue-devtools/dist/vue-devtools.d.ts +81 -0
- package/packages/vue3/node_modules/@intlify/vue-devtools/dist/vue-devtools.esm-bundler.js +18 -0
- package/packages/vue3/node_modules/@intlify/vue-devtools/index.js +7 -0
- package/packages/vue3/node_modules/@intlify/vue-devtools/package.json +51 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/api.d.ts +90 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/api.js +2 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/app.d.ts +1 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/app.js +2 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/component.d.ts +76 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/component.js +2 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/context.d.ts +5 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/context.js +2 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/hooks.d.ts +169 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/hooks.js +2 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/index.d.ts +6 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/index.js +18 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/util.d.ts +4 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/util.js +2 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/const.d.ts +1 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/const.js +4 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/env.d.ts +10 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/env.js +16 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/index.d.ts +14 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/index.js +31 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/esm/api/api.js +0 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/esm/api/app.js +0 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/esm/api/component.js +0 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/esm/api/context.js +0 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/esm/api/hooks.js +0 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/esm/api/index.js +6 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/esm/api/util.js +0 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/esm/const.js +1 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/esm/env.js +11 -0
- package/packages/vue3/node_modules/@vue/devtools-api/lib/esm/index.js +17 -0
- package/packages/vue3/node_modules/@vue/devtools-api/package.json +38 -0
- package/packages/vue3/node_modules/source-map/CHANGELOG.md +301 -0
- package/packages/vue3/node_modules/source-map/LICENSE +28 -0
- package/packages/vue3/node_modules/source-map/README.md +742 -0
- package/packages/vue3/node_modules/source-map/dist/source-map.debug.js +3234 -0
- package/packages/vue3/node_modules/source-map/dist/source-map.js +3233 -0
- package/packages/vue3/node_modules/source-map/dist/source-map.min.js +2 -0
- package/packages/vue3/node_modules/source-map/dist/source-map.min.js.map +1 -0
- package/packages/vue3/node_modules/source-map/lib/array-set.js +121 -0
- package/packages/vue3/node_modules/source-map/lib/base64-vlq.js +140 -0
- package/packages/vue3/node_modules/source-map/lib/base64.js +67 -0
- package/packages/vue3/node_modules/source-map/lib/binary-search.js +111 -0
- package/packages/vue3/node_modules/source-map/lib/mapping-list.js +79 -0
- package/packages/vue3/node_modules/source-map/lib/quick-sort.js +114 -0
- package/packages/vue3/node_modules/source-map/lib/source-map-consumer.js +1145 -0
- package/packages/vue3/node_modules/source-map/lib/source-map-generator.js +425 -0
- package/packages/vue3/node_modules/source-map/lib/source-node.js +413 -0
- package/packages/vue3/node_modules/source-map/lib/util.js +488 -0
- package/packages/vue3/node_modules/source-map/package.json +73 -0
- package/packages/vue3/node_modules/source-map/source-map.d.ts +98 -0
- package/packages/vue3/node_modules/source-map/source-map.js +8 -0
- package/packages/vue3/node_modules/vue-i18n/LICENSE +20 -0
- package/packages/vue3/node_modules/vue-i18n/README.md +74 -0
- package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.cjs.js +1801 -0
- package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.cjs.prod.js +1685 -0
- package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.d.ts +3302 -0
- package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.esm-browser.js +5052 -0
- package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.esm-browser.prod.js +6 -0
- package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.esm-bundler.js +2226 -0
- package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.global.js +5065 -0
- package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.global.prod.js +6 -0
- package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.runtime.esm-browser.js +3724 -0
- package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.runtime.esm-browser.prod.js +6 -0
- package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.runtime.esm-bundler.js +2224 -0
- package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.runtime.global.js +3737 -0
- package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.runtime.global.prod.js +6 -0
- package/packages/vue3/node_modules/vue-i18n/index.js +7 -0
- package/packages/vue3/node_modules/vue-i18n/package.json +69 -0
- package/packages/vue3/node_modules/vue-i18n/vetur/attributes.json +62 -0
- package/packages/vue3/node_modules/vue-i18n/vetur/tags.json +14 -0
- package/packages/vue3/package.json +15 -0
- package/packages/vue3/yarn.lock +79 -0
- package/packages/vuex/CHANGELOG.md +604 -0
- package/packages/vuex/LICENSE +21 -0
- package/packages/vuex/README.md +55 -0
- package/packages/vuex/dist/vuex.cjs.js +1474 -0
- package/packages/vuex/dist/vuex.esm-browser.js +1472 -0
- package/packages/vuex/dist/vuex.esm-browser.prod.js +1307 -0
- package/packages/vuex/dist/vuex.esm-bundler.js +1473 -0
- package/packages/vuex/dist/vuex.global.js +1499 -0
- package/packages/vuex/dist/vuex.global.prod.js +6 -0
- package/packages/vuex/dist/vuex.mjs +32 -0
- package/packages/vuex/package.json +99 -0
- package/packages/vuex/types/helpers.d.ts +86 -0
- package/packages/vuex/types/index.d.ts +167 -0
- package/packages/vuex/types/logger.d.ts +20 -0
- package/packages/vuex/types/vue.d.ts +12 -0
- package/packages/vuex3/CHANGELOG.md +356 -0
- package/packages/vuex3/LICENSE +21 -0
- package/packages/vuex3/README.md +59 -0
- package/packages/vuex3/dist/logger.js +155 -0
- package/packages/vuex3/dist/vuex.common.js +1244 -0
- package/packages/vuex3/dist/vuex.esm.browser.js +1200 -0
- package/packages/vuex3/dist/vuex.esm.browser.min.js +6 -0
- package/packages/vuex3/dist/vuex.esm.js +1243 -0
- package/packages/vuex3/dist/vuex.js +1250 -0
- package/packages/vuex3/dist/vuex.min.js +6 -0
- package/packages/vuex3/dist/vuex.mjs +26 -0
- package/packages/vuex3/package.json +96 -0
- package/packages/vuex3/types/helpers.d.ts +86 -0
- package/packages/vuex3/types/index.d.ts +164 -0
- package/packages/vuex3/types/logger.d.ts +20 -0
- package/packages/vuex3/types/vue.d.ts +18 -0
- package/packages/webpack-uni-app-loader/plugin/index.js +8 -2
- package/packages/webpack-uni-app-loader/view/main.js +12 -0
|
@@ -0,0 +1,989 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @intlify/core-base v9.1.7
|
|
3
|
+
* (c) 2021 kazuya kawaguchi
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
9
|
+
|
|
10
|
+
var messageResolver = require('@intlify/message-resolver');
|
|
11
|
+
var runtime = require('@intlify/runtime');
|
|
12
|
+
var messageCompiler = require('@intlify/message-compiler');
|
|
13
|
+
var shared = require('@intlify/shared');
|
|
14
|
+
var devtoolsIf = require('@intlify/devtools-if');
|
|
15
|
+
|
|
16
|
+
let devtools = null;
|
|
17
|
+
function setDevToolsHook(hook) {
|
|
18
|
+
devtools = hook;
|
|
19
|
+
}
|
|
20
|
+
function getDevToolsHook() {
|
|
21
|
+
return devtools;
|
|
22
|
+
}
|
|
23
|
+
function initI18nDevTools(i18n, version, meta) {
|
|
24
|
+
// TODO: queue if devtools is undefined
|
|
25
|
+
devtools &&
|
|
26
|
+
devtools.emit(devtoolsIf.IntlifyDevToolsHooks.I18nInit, {
|
|
27
|
+
timestamp: Date.now(),
|
|
28
|
+
i18n,
|
|
29
|
+
version,
|
|
30
|
+
meta
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
const translateDevTools = /* #__PURE__*/ createDevToolsHook(devtoolsIf.IntlifyDevToolsHooks.FunctionTranslate);
|
|
34
|
+
function createDevToolsHook(hook) {
|
|
35
|
+
return (payloads) => devtools && devtools.emit(hook, payloads);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** @internal */
|
|
39
|
+
const warnMessages = {
|
|
40
|
+
[0 /* NOT_FOUND_KEY */]: `Not found '{key}' key in '{locale}' locale messages.`,
|
|
41
|
+
[1 /* FALLBACK_TO_TRANSLATE */]: `Fall back to translate '{key}' key with '{target}' locale.`,
|
|
42
|
+
[2 /* CANNOT_FORMAT_NUMBER */]: `Cannot format a number value due to not supported Intl.NumberFormat.`,
|
|
43
|
+
[3 /* FALLBACK_TO_NUMBER_FORMAT */]: `Fall back to number format '{key}' key with '{target}' locale.`,
|
|
44
|
+
[4 /* CANNOT_FORMAT_DATE */]: `Cannot format a date value due to not supported Intl.DateTimeFormat.`,
|
|
45
|
+
[5 /* FALLBACK_TO_DATE_FORMAT */]: `Fall back to datetime format '{key}' key with '{target}' locale.`
|
|
46
|
+
};
|
|
47
|
+
function getWarnMessage(code, ...args) {
|
|
48
|
+
return shared.format(warnMessages[code], ...args);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Intlify core-base version
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
const VERSION = '9.1.7';
|
|
56
|
+
const NOT_REOSLVED = -1;
|
|
57
|
+
const MISSING_RESOLVE_VALUE = '';
|
|
58
|
+
function getDefaultLinkedModifiers() {
|
|
59
|
+
return {
|
|
60
|
+
upper: (val) => (shared.isString(val) ? val.toUpperCase() : val),
|
|
61
|
+
lower: (val) => (shared.isString(val) ? val.toLowerCase() : val),
|
|
62
|
+
// prettier-ignore
|
|
63
|
+
capitalize: (val) => (shared.isString(val)
|
|
64
|
+
? `${val.charAt(0).toLocaleUpperCase()}${val.substr(1)}`
|
|
65
|
+
: val)
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
let _compiler;
|
|
69
|
+
function registerMessageCompiler(compiler) {
|
|
70
|
+
_compiler = compiler;
|
|
71
|
+
}
|
|
72
|
+
// Additional Meta for Intlify DevTools
|
|
73
|
+
let _additionalMeta = null;
|
|
74
|
+
const setAdditionalMeta = /* #__PURE__*/ (meta) => {
|
|
75
|
+
_additionalMeta = meta;
|
|
76
|
+
};
|
|
77
|
+
const getAdditionalMeta = /* #__PURE__*/ () => _additionalMeta;
|
|
78
|
+
// ID for CoreContext
|
|
79
|
+
let _cid = 0;
|
|
80
|
+
function createCoreContext(options = {}) {
|
|
81
|
+
// setup options
|
|
82
|
+
const version = shared.isString(options.version) ? options.version : VERSION;
|
|
83
|
+
const locale = shared.isString(options.locale) ? options.locale : 'en-US';
|
|
84
|
+
const fallbackLocale = shared.isArray(options.fallbackLocale) ||
|
|
85
|
+
shared.isPlainObject(options.fallbackLocale) ||
|
|
86
|
+
shared.isString(options.fallbackLocale) ||
|
|
87
|
+
options.fallbackLocale === false
|
|
88
|
+
? options.fallbackLocale
|
|
89
|
+
: locale;
|
|
90
|
+
const messages = shared.isPlainObject(options.messages)
|
|
91
|
+
? options.messages
|
|
92
|
+
: { [locale]: {} };
|
|
93
|
+
const datetimeFormats = shared.isPlainObject(options.datetimeFormats)
|
|
94
|
+
? options.datetimeFormats
|
|
95
|
+
: { [locale]: {} };
|
|
96
|
+
const numberFormats = shared.isPlainObject(options.numberFormats)
|
|
97
|
+
? options.numberFormats
|
|
98
|
+
: { [locale]: {} };
|
|
99
|
+
const modifiers = shared.assign({}, options.modifiers || {}, getDefaultLinkedModifiers());
|
|
100
|
+
const pluralRules = options.pluralRules || {};
|
|
101
|
+
const missing = shared.isFunction(options.missing) ? options.missing : null;
|
|
102
|
+
const missingWarn = shared.isBoolean(options.missingWarn) || shared.isRegExp(options.missingWarn)
|
|
103
|
+
? options.missingWarn
|
|
104
|
+
: true;
|
|
105
|
+
const fallbackWarn = shared.isBoolean(options.fallbackWarn) || shared.isRegExp(options.fallbackWarn)
|
|
106
|
+
? options.fallbackWarn
|
|
107
|
+
: true;
|
|
108
|
+
const fallbackFormat = !!options.fallbackFormat;
|
|
109
|
+
const unresolving = !!options.unresolving;
|
|
110
|
+
const postTranslation = shared.isFunction(options.postTranslation)
|
|
111
|
+
? options.postTranslation
|
|
112
|
+
: null;
|
|
113
|
+
const processor = shared.isPlainObject(options.processor) ? options.processor : null;
|
|
114
|
+
const warnHtmlMessage = shared.isBoolean(options.warnHtmlMessage)
|
|
115
|
+
? options.warnHtmlMessage
|
|
116
|
+
: true;
|
|
117
|
+
const escapeParameter = !!options.escapeParameter;
|
|
118
|
+
const messageCompiler = shared.isFunction(options.messageCompiler)
|
|
119
|
+
? options.messageCompiler
|
|
120
|
+
: _compiler;
|
|
121
|
+
const onWarn = shared.isFunction(options.onWarn) ? options.onWarn : shared.warn;
|
|
122
|
+
// setup internal options
|
|
123
|
+
const internalOptions = options;
|
|
124
|
+
const __datetimeFormatters = shared.isObject(internalOptions.__datetimeFormatters)
|
|
125
|
+
? internalOptions.__datetimeFormatters
|
|
126
|
+
: new Map();
|
|
127
|
+
const __numberFormatters = shared.isObject(internalOptions.__numberFormatters)
|
|
128
|
+
? internalOptions.__numberFormatters
|
|
129
|
+
: new Map();
|
|
130
|
+
const __meta = shared.isObject(internalOptions.__meta) ? internalOptions.__meta : {};
|
|
131
|
+
_cid++;
|
|
132
|
+
const context = {
|
|
133
|
+
version,
|
|
134
|
+
cid: _cid,
|
|
135
|
+
locale,
|
|
136
|
+
fallbackLocale,
|
|
137
|
+
messages,
|
|
138
|
+
datetimeFormats,
|
|
139
|
+
numberFormats,
|
|
140
|
+
modifiers,
|
|
141
|
+
pluralRules,
|
|
142
|
+
missing,
|
|
143
|
+
missingWarn,
|
|
144
|
+
fallbackWarn,
|
|
145
|
+
fallbackFormat,
|
|
146
|
+
unresolving,
|
|
147
|
+
postTranslation,
|
|
148
|
+
processor,
|
|
149
|
+
warnHtmlMessage,
|
|
150
|
+
escapeParameter,
|
|
151
|
+
messageCompiler,
|
|
152
|
+
onWarn,
|
|
153
|
+
__datetimeFormatters,
|
|
154
|
+
__numberFormatters,
|
|
155
|
+
__meta
|
|
156
|
+
};
|
|
157
|
+
// for vue-devtools timeline event
|
|
158
|
+
{
|
|
159
|
+
context.__v_emitter =
|
|
160
|
+
internalOptions.__v_emitter != null
|
|
161
|
+
? internalOptions.__v_emitter
|
|
162
|
+
: undefined;
|
|
163
|
+
}
|
|
164
|
+
// NOTE: experimental !!
|
|
165
|
+
{
|
|
166
|
+
initI18nDevTools(context, version, __meta);
|
|
167
|
+
}
|
|
168
|
+
return context;
|
|
169
|
+
}
|
|
170
|
+
/** @internal */
|
|
171
|
+
function isTranslateFallbackWarn(fallback, key) {
|
|
172
|
+
return fallback instanceof RegExp ? fallback.test(key) : fallback;
|
|
173
|
+
}
|
|
174
|
+
/** @internal */
|
|
175
|
+
function isTranslateMissingWarn(missing, key) {
|
|
176
|
+
return missing instanceof RegExp ? missing.test(key) : missing;
|
|
177
|
+
}
|
|
178
|
+
/** @internal */
|
|
179
|
+
function handleMissing(context, key, locale, missingWarn, type) {
|
|
180
|
+
const { missing, onWarn } = context;
|
|
181
|
+
// for vue-devtools timeline event
|
|
182
|
+
{
|
|
183
|
+
const emitter = context.__v_emitter;
|
|
184
|
+
if (emitter) {
|
|
185
|
+
emitter.emit("missing" /* MISSING */, {
|
|
186
|
+
locale,
|
|
187
|
+
key,
|
|
188
|
+
type,
|
|
189
|
+
groupId: `${type}:${key}`
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (missing !== null) {
|
|
194
|
+
const ret = missing(context, locale, key, type);
|
|
195
|
+
return shared.isString(ret) ? ret : key;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
if (isTranslateMissingWarn(missingWarn, key)) {
|
|
199
|
+
onWarn(getWarnMessage(0 /* NOT_FOUND_KEY */, { key, locale }));
|
|
200
|
+
}
|
|
201
|
+
return key;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/** @internal */
|
|
205
|
+
function getLocaleChain(ctx, fallback, start) {
|
|
206
|
+
const context = ctx;
|
|
207
|
+
if (!context.__localeChainCache) {
|
|
208
|
+
context.__localeChainCache = new Map();
|
|
209
|
+
}
|
|
210
|
+
let chain = context.__localeChainCache.get(start);
|
|
211
|
+
if (!chain) {
|
|
212
|
+
chain = [];
|
|
213
|
+
// first block defined by start
|
|
214
|
+
let block = [start];
|
|
215
|
+
// while any intervening block found
|
|
216
|
+
while (shared.isArray(block)) {
|
|
217
|
+
block = appendBlockToChain(chain, block, fallback);
|
|
218
|
+
}
|
|
219
|
+
// prettier-ignore
|
|
220
|
+
// last block defined by default
|
|
221
|
+
const defaults = shared.isArray(fallback)
|
|
222
|
+
? fallback
|
|
223
|
+
: shared.isPlainObject(fallback)
|
|
224
|
+
? fallback['default']
|
|
225
|
+
? fallback['default']
|
|
226
|
+
: null
|
|
227
|
+
: fallback;
|
|
228
|
+
// convert defaults to array
|
|
229
|
+
block = shared.isString(defaults) ? [defaults] : defaults;
|
|
230
|
+
if (shared.isArray(block)) {
|
|
231
|
+
appendBlockToChain(chain, block, false);
|
|
232
|
+
}
|
|
233
|
+
context.__localeChainCache.set(start, chain);
|
|
234
|
+
}
|
|
235
|
+
return chain;
|
|
236
|
+
}
|
|
237
|
+
function appendBlockToChain(chain, block, blocks) {
|
|
238
|
+
let follow = true;
|
|
239
|
+
for (let i = 0; i < block.length && shared.isBoolean(follow); i++) {
|
|
240
|
+
const locale = block[i];
|
|
241
|
+
if (shared.isString(locale)) {
|
|
242
|
+
follow = appendLocaleToChain(chain, block[i], blocks);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return follow;
|
|
246
|
+
}
|
|
247
|
+
function appendLocaleToChain(chain, locale, blocks) {
|
|
248
|
+
let follow;
|
|
249
|
+
const tokens = locale.split('-');
|
|
250
|
+
do {
|
|
251
|
+
const target = tokens.join('-');
|
|
252
|
+
follow = appendItemToChain(chain, target, blocks);
|
|
253
|
+
tokens.splice(-1, 1);
|
|
254
|
+
} while (tokens.length && follow === true);
|
|
255
|
+
return follow;
|
|
256
|
+
}
|
|
257
|
+
function appendItemToChain(chain, target, blocks) {
|
|
258
|
+
let follow = false;
|
|
259
|
+
if (!chain.includes(target)) {
|
|
260
|
+
follow = true;
|
|
261
|
+
if (target) {
|
|
262
|
+
follow = target[target.length - 1] !== '!';
|
|
263
|
+
const locale = target.replace(/!/g, '');
|
|
264
|
+
chain.push(locale);
|
|
265
|
+
if ((shared.isArray(blocks) || shared.isPlainObject(blocks)) &&
|
|
266
|
+
blocks[locale] // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
267
|
+
) {
|
|
268
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
269
|
+
follow = blocks[locale];
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return follow;
|
|
274
|
+
}
|
|
275
|
+
/** @internal */
|
|
276
|
+
function updateFallbackLocale(ctx, locale, fallback) {
|
|
277
|
+
const context = ctx;
|
|
278
|
+
context.__localeChainCache = new Map();
|
|
279
|
+
getLocaleChain(ctx, fallback, locale);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const RE_HTML_TAG = /<\/?[\w\s="/.':;#-\/]+>/;
|
|
283
|
+
const WARN_MESSAGE = `Detected HTML in '{source}' message. Recommend not using HTML messages to avoid XSS.`;
|
|
284
|
+
function checkHtmlMessage(source, options) {
|
|
285
|
+
const warnHtmlMessage = shared.isBoolean(options.warnHtmlMessage)
|
|
286
|
+
? options.warnHtmlMessage
|
|
287
|
+
: true;
|
|
288
|
+
if (warnHtmlMessage && RE_HTML_TAG.test(source)) {
|
|
289
|
+
shared.warn(shared.format(WARN_MESSAGE, { source }));
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
const defaultOnCacheKey = (source) => source;
|
|
293
|
+
let compileCache = Object.create(null);
|
|
294
|
+
function clearCompileCache() {
|
|
295
|
+
compileCache = Object.create(null);
|
|
296
|
+
}
|
|
297
|
+
function compileToFunction(source, options = {}) {
|
|
298
|
+
{
|
|
299
|
+
// check HTML message
|
|
300
|
+
checkHtmlMessage(source, options);
|
|
301
|
+
// check caches
|
|
302
|
+
const onCacheKey = options.onCacheKey || defaultOnCacheKey;
|
|
303
|
+
const key = onCacheKey(source);
|
|
304
|
+
const cached = compileCache[key];
|
|
305
|
+
if (cached) {
|
|
306
|
+
return cached;
|
|
307
|
+
}
|
|
308
|
+
// compile error detecting
|
|
309
|
+
let occurred = false;
|
|
310
|
+
const onError = options.onError || messageCompiler.defaultOnError;
|
|
311
|
+
options.onError = (err) => {
|
|
312
|
+
occurred = true;
|
|
313
|
+
onError(err);
|
|
314
|
+
};
|
|
315
|
+
// compile
|
|
316
|
+
const { code } = messageCompiler.baseCompile(source, options);
|
|
317
|
+
// evaluate function
|
|
318
|
+
const msg = new Function(`return ${code}`)();
|
|
319
|
+
// if occurred compile error, don't cache
|
|
320
|
+
return !occurred ? (compileCache[key] = msg) : msg;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function createCoreError(code) {
|
|
325
|
+
return messageCompiler.createCompileError(code, null, { messages: errorMessages } );
|
|
326
|
+
}
|
|
327
|
+
/** @internal */
|
|
328
|
+
const errorMessages = {
|
|
329
|
+
[14 /* INVALID_ARGUMENT */]: 'Invalid arguments',
|
|
330
|
+
[15 /* INVALID_DATE_ARGUMENT */]: 'The date provided is an invalid Date object.' +
|
|
331
|
+
'Make sure your Date represents a valid date.',
|
|
332
|
+
[16 /* INVALID_ISO_DATE_ARGUMENT */]: 'The argument provided is not a valid ISO date string'
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
const NOOP_MESSAGE_FUNCTION = () => '';
|
|
336
|
+
const isMessageFunction = (val) => shared.isFunction(val);
|
|
337
|
+
// implementation of `translate` function
|
|
338
|
+
function translate(context, ...args) {
|
|
339
|
+
const { fallbackFormat, postTranslation, unresolving, fallbackLocale, messages } = context;
|
|
340
|
+
const [key, options] = parseTranslateArgs(...args);
|
|
341
|
+
const missingWarn = shared.isBoolean(options.missingWarn)
|
|
342
|
+
? options.missingWarn
|
|
343
|
+
: context.missingWarn;
|
|
344
|
+
const fallbackWarn = shared.isBoolean(options.fallbackWarn)
|
|
345
|
+
? options.fallbackWarn
|
|
346
|
+
: context.fallbackWarn;
|
|
347
|
+
const escapeParameter = shared.isBoolean(options.escapeParameter)
|
|
348
|
+
? options.escapeParameter
|
|
349
|
+
: context.escapeParameter;
|
|
350
|
+
const resolvedMessage = !!options.resolvedMessage;
|
|
351
|
+
// prettier-ignore
|
|
352
|
+
const defaultMsgOrKey = shared.isString(options.default) || shared.isBoolean(options.default) // default by function option
|
|
353
|
+
? !shared.isBoolean(options.default)
|
|
354
|
+
? options.default
|
|
355
|
+
: key
|
|
356
|
+
: fallbackFormat // default by `fallbackFormat` option
|
|
357
|
+
? key
|
|
358
|
+
: '';
|
|
359
|
+
const enableDefaultMsg = fallbackFormat || defaultMsgOrKey !== '';
|
|
360
|
+
const locale = shared.isString(options.locale) ? options.locale : context.locale;
|
|
361
|
+
// escape params
|
|
362
|
+
escapeParameter && escapeParams(options);
|
|
363
|
+
// resolve message format
|
|
364
|
+
// eslint-disable-next-line prefer-const
|
|
365
|
+
let [format, targetLocale, message] = !resolvedMessage
|
|
366
|
+
? resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn)
|
|
367
|
+
: [
|
|
368
|
+
key,
|
|
369
|
+
locale,
|
|
370
|
+
messages[locale] || {}
|
|
371
|
+
];
|
|
372
|
+
// if you use default message, set it as message format!
|
|
373
|
+
let cacheBaseKey = key;
|
|
374
|
+
if (!resolvedMessage &&
|
|
375
|
+
!(shared.isString(format) || isMessageFunction(format))) {
|
|
376
|
+
if (enableDefaultMsg) {
|
|
377
|
+
format = defaultMsgOrKey;
|
|
378
|
+
cacheBaseKey = format;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
// checking message format and target locale
|
|
382
|
+
if (!resolvedMessage &&
|
|
383
|
+
(!(shared.isString(format) || isMessageFunction(format)) ||
|
|
384
|
+
!shared.isString(targetLocale))) {
|
|
385
|
+
return unresolving ? NOT_REOSLVED : key;
|
|
386
|
+
}
|
|
387
|
+
if (shared.isString(format) && context.messageCompiler == null) {
|
|
388
|
+
shared.warn(`The message format compilation is not supported in this build. ` +
|
|
389
|
+
`Because message compiler isn't included. ` +
|
|
390
|
+
`You need to pre-compilation all message format. ` +
|
|
391
|
+
`So translate function return '${key}'.`);
|
|
392
|
+
return key;
|
|
393
|
+
}
|
|
394
|
+
// setup compile error detecting
|
|
395
|
+
let occurred = false;
|
|
396
|
+
const errorDetector = () => {
|
|
397
|
+
occurred = true;
|
|
398
|
+
};
|
|
399
|
+
// compile message format
|
|
400
|
+
const msg = !isMessageFunction(format)
|
|
401
|
+
? compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, errorDetector)
|
|
402
|
+
: format;
|
|
403
|
+
// if occurred compile error, return the message format
|
|
404
|
+
if (occurred) {
|
|
405
|
+
return format;
|
|
406
|
+
}
|
|
407
|
+
// evaluate message with context
|
|
408
|
+
const ctxOptions = getMessageContextOptions(context, targetLocale, message, options);
|
|
409
|
+
const msgContext = runtime.createMessageContext(ctxOptions);
|
|
410
|
+
const messaged = evaluateMessage(context, msg, msgContext);
|
|
411
|
+
// if use post translation option, proceed it with handler
|
|
412
|
+
const ret = postTranslation ? postTranslation(messaged) : messaged;
|
|
413
|
+
// NOTE: experimental !!
|
|
414
|
+
{
|
|
415
|
+
// prettier-ignore
|
|
416
|
+
const payloads = {
|
|
417
|
+
timestamp: Date.now(),
|
|
418
|
+
key: shared.isString(key)
|
|
419
|
+
? key
|
|
420
|
+
: isMessageFunction(format)
|
|
421
|
+
? format.key
|
|
422
|
+
: '',
|
|
423
|
+
locale: targetLocale || (isMessageFunction(format)
|
|
424
|
+
? format.locale
|
|
425
|
+
: ''),
|
|
426
|
+
format: shared.isString(format)
|
|
427
|
+
? format
|
|
428
|
+
: isMessageFunction(format)
|
|
429
|
+
? format.source
|
|
430
|
+
: '',
|
|
431
|
+
message: ret
|
|
432
|
+
};
|
|
433
|
+
payloads.meta = shared.assign({}, context.__meta, getAdditionalMeta() || {});
|
|
434
|
+
translateDevTools(payloads);
|
|
435
|
+
}
|
|
436
|
+
return ret;
|
|
437
|
+
}
|
|
438
|
+
function escapeParams(options) {
|
|
439
|
+
if (shared.isArray(options.list)) {
|
|
440
|
+
options.list = options.list.map(item => shared.isString(item) ? shared.escapeHtml(item) : item);
|
|
441
|
+
}
|
|
442
|
+
else if (shared.isObject(options.named)) {
|
|
443
|
+
Object.keys(options.named).forEach(key => {
|
|
444
|
+
if (shared.isString(options.named[key])) {
|
|
445
|
+
options.named[key] = shared.escapeHtml(options.named[key]);
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn) {
|
|
451
|
+
const { messages, onWarn } = context;
|
|
452
|
+
const locales = getLocaleChain(context, fallbackLocale, locale);
|
|
453
|
+
let message = {};
|
|
454
|
+
let targetLocale;
|
|
455
|
+
let format = null;
|
|
456
|
+
let from = locale;
|
|
457
|
+
let to = null;
|
|
458
|
+
const type = 'translate';
|
|
459
|
+
for (let i = 0; i < locales.length; i++) {
|
|
460
|
+
targetLocale = to = locales[i];
|
|
461
|
+
if (locale !== targetLocale &&
|
|
462
|
+
isTranslateFallbackWarn(fallbackWarn, key)) {
|
|
463
|
+
onWarn(getWarnMessage(1 /* FALLBACK_TO_TRANSLATE */, {
|
|
464
|
+
key,
|
|
465
|
+
target: targetLocale
|
|
466
|
+
}));
|
|
467
|
+
}
|
|
468
|
+
// for vue-devtools timeline event
|
|
469
|
+
if (locale !== targetLocale) {
|
|
470
|
+
const emitter = context.__v_emitter;
|
|
471
|
+
if (emitter) {
|
|
472
|
+
emitter.emit("fallback" /* FALBACK */, {
|
|
473
|
+
type,
|
|
474
|
+
key,
|
|
475
|
+
from,
|
|
476
|
+
to,
|
|
477
|
+
groupId: `${type}:${key}`
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
message =
|
|
482
|
+
messages[targetLocale] || {};
|
|
483
|
+
// for vue-devtools timeline event
|
|
484
|
+
let start = null;
|
|
485
|
+
let startTag;
|
|
486
|
+
let endTag;
|
|
487
|
+
if (shared.inBrowser) {
|
|
488
|
+
start = window.performance.now();
|
|
489
|
+
startTag = 'intlify-message-resolve-start';
|
|
490
|
+
endTag = 'intlify-message-resolve-end';
|
|
491
|
+
shared.mark && shared.mark(startTag);
|
|
492
|
+
}
|
|
493
|
+
if ((format = messageResolver.resolveValue(message, key)) === null) {
|
|
494
|
+
// if null, resolve with object key path
|
|
495
|
+
format = message[key]; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
496
|
+
}
|
|
497
|
+
// for vue-devtools timeline event
|
|
498
|
+
if (shared.inBrowser) {
|
|
499
|
+
const end = window.performance.now();
|
|
500
|
+
const emitter = context.__v_emitter;
|
|
501
|
+
if (emitter && start && format) {
|
|
502
|
+
emitter.emit("message-resolve" /* MESSAGE_RESOLVE */, {
|
|
503
|
+
type: "message-resolve" /* MESSAGE_RESOLVE */,
|
|
504
|
+
key,
|
|
505
|
+
message: format,
|
|
506
|
+
time: end - start,
|
|
507
|
+
groupId: `${type}:${key}`
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
if (startTag && endTag && shared.mark && shared.measure) {
|
|
511
|
+
shared.mark(endTag);
|
|
512
|
+
shared.measure('intlify message resolve', startTag, endTag);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
if (shared.isString(format) || shared.isFunction(format))
|
|
516
|
+
break;
|
|
517
|
+
const missingRet = handleMissing(context, key, targetLocale, missingWarn, type);
|
|
518
|
+
if (missingRet !== key) {
|
|
519
|
+
format = missingRet;
|
|
520
|
+
}
|
|
521
|
+
from = to;
|
|
522
|
+
}
|
|
523
|
+
return [format, targetLocale, message];
|
|
524
|
+
}
|
|
525
|
+
function compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, errorDetector) {
|
|
526
|
+
const { messageCompiler, warnHtmlMessage } = context;
|
|
527
|
+
if (isMessageFunction(format)) {
|
|
528
|
+
const msg = format;
|
|
529
|
+
msg.locale = msg.locale || targetLocale;
|
|
530
|
+
msg.key = msg.key || key;
|
|
531
|
+
return msg;
|
|
532
|
+
}
|
|
533
|
+
// for vue-devtools timeline event
|
|
534
|
+
let start = null;
|
|
535
|
+
let startTag;
|
|
536
|
+
let endTag;
|
|
537
|
+
if (shared.inBrowser) {
|
|
538
|
+
start = window.performance.now();
|
|
539
|
+
startTag = 'intlify-message-compilation-start';
|
|
540
|
+
endTag = 'intlify-message-compilation-end';
|
|
541
|
+
shared.mark && shared.mark(startTag);
|
|
542
|
+
}
|
|
543
|
+
const msg = messageCompiler(format, getCompileOptions(context, targetLocale, cacheBaseKey, format, warnHtmlMessage, errorDetector));
|
|
544
|
+
// for vue-devtools timeline event
|
|
545
|
+
if (shared.inBrowser) {
|
|
546
|
+
const end = window.performance.now();
|
|
547
|
+
const emitter = context.__v_emitter;
|
|
548
|
+
if (emitter && start) {
|
|
549
|
+
emitter.emit("message-compilation" /* MESSAGE_COMPILATION */, {
|
|
550
|
+
type: "message-compilation" /* MESSAGE_COMPILATION */,
|
|
551
|
+
message: format,
|
|
552
|
+
time: end - start,
|
|
553
|
+
groupId: `${'translate'}:${key}`
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
if (startTag && endTag && shared.mark && shared.measure) {
|
|
557
|
+
shared.mark(endTag);
|
|
558
|
+
shared.measure('intlify message compilation', startTag, endTag);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
msg.locale = targetLocale;
|
|
562
|
+
msg.key = key;
|
|
563
|
+
msg.source = format;
|
|
564
|
+
return msg;
|
|
565
|
+
}
|
|
566
|
+
function evaluateMessage(context, msg, msgCtx) {
|
|
567
|
+
// for vue-devtools timeline event
|
|
568
|
+
let start = null;
|
|
569
|
+
let startTag;
|
|
570
|
+
let endTag;
|
|
571
|
+
if (shared.inBrowser) {
|
|
572
|
+
start = window.performance.now();
|
|
573
|
+
startTag = 'intlify-message-evaluation-start';
|
|
574
|
+
endTag = 'intlify-message-evaluation-end';
|
|
575
|
+
shared.mark && shared.mark(startTag);
|
|
576
|
+
}
|
|
577
|
+
const messaged = msg(msgCtx);
|
|
578
|
+
// for vue-devtools timeline event
|
|
579
|
+
if (shared.inBrowser) {
|
|
580
|
+
const end = window.performance.now();
|
|
581
|
+
const emitter = context.__v_emitter;
|
|
582
|
+
if (emitter && start) {
|
|
583
|
+
emitter.emit("message-evaluation" /* MESSAGE_EVALUATION */, {
|
|
584
|
+
type: "message-evaluation" /* MESSAGE_EVALUATION */,
|
|
585
|
+
value: messaged,
|
|
586
|
+
time: end - start,
|
|
587
|
+
groupId: `${'translate'}:${msg.key}`
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
if (startTag && endTag && shared.mark && shared.measure) {
|
|
591
|
+
shared.mark(endTag);
|
|
592
|
+
shared.measure('intlify message evaluation', startTag, endTag);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
return messaged;
|
|
596
|
+
}
|
|
597
|
+
/** @internal */
|
|
598
|
+
function parseTranslateArgs(...args) {
|
|
599
|
+
const [arg1, arg2, arg3] = args;
|
|
600
|
+
const options = {};
|
|
601
|
+
if (!shared.isString(arg1) && !shared.isNumber(arg1) && !isMessageFunction(arg1)) {
|
|
602
|
+
throw createCoreError(14 /* INVALID_ARGUMENT */);
|
|
603
|
+
}
|
|
604
|
+
// prettier-ignore
|
|
605
|
+
const key = shared.isNumber(arg1)
|
|
606
|
+
? String(arg1)
|
|
607
|
+
: isMessageFunction(arg1)
|
|
608
|
+
? arg1
|
|
609
|
+
: arg1;
|
|
610
|
+
if (shared.isNumber(arg2)) {
|
|
611
|
+
options.plural = arg2;
|
|
612
|
+
}
|
|
613
|
+
else if (shared.isString(arg2)) {
|
|
614
|
+
options.default = arg2;
|
|
615
|
+
}
|
|
616
|
+
else if (shared.isPlainObject(arg2) && !shared.isEmptyObject(arg2)) {
|
|
617
|
+
options.named = arg2;
|
|
618
|
+
}
|
|
619
|
+
else if (shared.isArray(arg2)) {
|
|
620
|
+
options.list = arg2;
|
|
621
|
+
}
|
|
622
|
+
if (shared.isNumber(arg3)) {
|
|
623
|
+
options.plural = arg3;
|
|
624
|
+
}
|
|
625
|
+
else if (shared.isString(arg3)) {
|
|
626
|
+
options.default = arg3;
|
|
627
|
+
}
|
|
628
|
+
else if (shared.isPlainObject(arg3)) {
|
|
629
|
+
shared.assign(options, arg3);
|
|
630
|
+
}
|
|
631
|
+
return [key, options];
|
|
632
|
+
}
|
|
633
|
+
function getCompileOptions(context, locale, key, source, warnHtmlMessage, errorDetector) {
|
|
634
|
+
return {
|
|
635
|
+
warnHtmlMessage,
|
|
636
|
+
onError: (err) => {
|
|
637
|
+
errorDetector && errorDetector(err);
|
|
638
|
+
{
|
|
639
|
+
const message = `Message compilation error: ${err.message}`;
|
|
640
|
+
const codeFrame = err.location &&
|
|
641
|
+
shared.generateCodeFrame(source, err.location.start.offset, err.location.end.offset);
|
|
642
|
+
const emitter = context
|
|
643
|
+
.__v_emitter;
|
|
644
|
+
if (emitter) {
|
|
645
|
+
emitter.emit("compile-error" /* COMPILE_ERROR */, {
|
|
646
|
+
message: source,
|
|
647
|
+
error: err.message,
|
|
648
|
+
start: err.location && err.location.start.offset,
|
|
649
|
+
end: err.location && err.location.end.offset,
|
|
650
|
+
groupId: `${'translate'}:${key}`
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
console.error(codeFrame ? `${message}\n${codeFrame}` : message);
|
|
654
|
+
}
|
|
655
|
+
},
|
|
656
|
+
onCacheKey: (source) => shared.generateFormatCacheKey(locale, key, source)
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
function getMessageContextOptions(context, locale, message, options) {
|
|
660
|
+
const { modifiers, pluralRules } = context;
|
|
661
|
+
const resolveMessage = (key) => {
|
|
662
|
+
const val = messageResolver.resolveValue(message, key);
|
|
663
|
+
if (shared.isString(val)) {
|
|
664
|
+
let occurred = false;
|
|
665
|
+
const errorDetector = () => {
|
|
666
|
+
occurred = true;
|
|
667
|
+
};
|
|
668
|
+
const msg = compileMessageFormat(context, key, locale, val, key, errorDetector);
|
|
669
|
+
return !occurred
|
|
670
|
+
? msg
|
|
671
|
+
: NOOP_MESSAGE_FUNCTION;
|
|
672
|
+
}
|
|
673
|
+
else if (isMessageFunction(val)) {
|
|
674
|
+
return val;
|
|
675
|
+
}
|
|
676
|
+
else {
|
|
677
|
+
// TODO: should be implemented warning message
|
|
678
|
+
return NOOP_MESSAGE_FUNCTION;
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
const ctxOptions = {
|
|
682
|
+
locale,
|
|
683
|
+
modifiers,
|
|
684
|
+
pluralRules,
|
|
685
|
+
messages: resolveMessage
|
|
686
|
+
};
|
|
687
|
+
if (context.processor) {
|
|
688
|
+
ctxOptions.processor = context.processor;
|
|
689
|
+
}
|
|
690
|
+
if (options.list) {
|
|
691
|
+
ctxOptions.list = options.list;
|
|
692
|
+
}
|
|
693
|
+
if (options.named) {
|
|
694
|
+
ctxOptions.named = options.named;
|
|
695
|
+
}
|
|
696
|
+
if (shared.isNumber(options.plural)) {
|
|
697
|
+
ctxOptions.pluralIndex = options.plural;
|
|
698
|
+
}
|
|
699
|
+
return ctxOptions;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
const intlDefined = typeof Intl !== 'undefined';
|
|
703
|
+
const Availabilities = {
|
|
704
|
+
dateTimeFormat: intlDefined && typeof Intl.DateTimeFormat !== 'undefined',
|
|
705
|
+
numberFormat: intlDefined && typeof Intl.NumberFormat !== 'undefined'
|
|
706
|
+
};
|
|
707
|
+
|
|
708
|
+
// implementation of `datetime` function
|
|
709
|
+
function datetime(context, ...args) {
|
|
710
|
+
const { datetimeFormats, unresolving, fallbackLocale, onWarn } = context;
|
|
711
|
+
const { __datetimeFormatters } = context;
|
|
712
|
+
if (!Availabilities.dateTimeFormat) {
|
|
713
|
+
onWarn(getWarnMessage(4 /* CANNOT_FORMAT_DATE */));
|
|
714
|
+
return MISSING_RESOLVE_VALUE;
|
|
715
|
+
}
|
|
716
|
+
const [key, value, options, overrides] = parseDateTimeArgs(...args);
|
|
717
|
+
const missingWarn = shared.isBoolean(options.missingWarn)
|
|
718
|
+
? options.missingWarn
|
|
719
|
+
: context.missingWarn;
|
|
720
|
+
const fallbackWarn = shared.isBoolean(options.fallbackWarn)
|
|
721
|
+
? options.fallbackWarn
|
|
722
|
+
: context.fallbackWarn;
|
|
723
|
+
const part = !!options.part;
|
|
724
|
+
const locale = shared.isString(options.locale) ? options.locale : context.locale;
|
|
725
|
+
const locales = getLocaleChain(context, fallbackLocale, locale);
|
|
726
|
+
if (!shared.isString(key) || key === '') {
|
|
727
|
+
return new Intl.DateTimeFormat(locale).format(value);
|
|
728
|
+
}
|
|
729
|
+
// resolve format
|
|
730
|
+
let datetimeFormat = {};
|
|
731
|
+
let targetLocale;
|
|
732
|
+
let format = null;
|
|
733
|
+
let from = locale;
|
|
734
|
+
let to = null;
|
|
735
|
+
const type = 'datetime format';
|
|
736
|
+
for (let i = 0; i < locales.length; i++) {
|
|
737
|
+
targetLocale = to = locales[i];
|
|
738
|
+
if (locale !== targetLocale &&
|
|
739
|
+
isTranslateFallbackWarn(fallbackWarn, key)) {
|
|
740
|
+
onWarn(getWarnMessage(5 /* FALLBACK_TO_DATE_FORMAT */, {
|
|
741
|
+
key,
|
|
742
|
+
target: targetLocale
|
|
743
|
+
}));
|
|
744
|
+
}
|
|
745
|
+
// for vue-devtools timeline event
|
|
746
|
+
if (locale !== targetLocale) {
|
|
747
|
+
const emitter = context.__v_emitter;
|
|
748
|
+
if (emitter) {
|
|
749
|
+
emitter.emit("fallback" /* FALBACK */, {
|
|
750
|
+
type,
|
|
751
|
+
key,
|
|
752
|
+
from,
|
|
753
|
+
to,
|
|
754
|
+
groupId: `${type}:${key}`
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
datetimeFormat =
|
|
759
|
+
datetimeFormats[targetLocale] || {};
|
|
760
|
+
format = datetimeFormat[key];
|
|
761
|
+
if (shared.isPlainObject(format))
|
|
762
|
+
break;
|
|
763
|
+
handleMissing(context, key, targetLocale, missingWarn, type);
|
|
764
|
+
from = to;
|
|
765
|
+
}
|
|
766
|
+
// checking format and target locale
|
|
767
|
+
if (!shared.isPlainObject(format) || !shared.isString(targetLocale)) {
|
|
768
|
+
return unresolving ? NOT_REOSLVED : key;
|
|
769
|
+
}
|
|
770
|
+
let id = `${targetLocale}__${key}`;
|
|
771
|
+
if (!shared.isEmptyObject(overrides)) {
|
|
772
|
+
id = `${id}__${JSON.stringify(overrides)}`;
|
|
773
|
+
}
|
|
774
|
+
let formatter = __datetimeFormatters.get(id);
|
|
775
|
+
if (!formatter) {
|
|
776
|
+
formatter = new Intl.DateTimeFormat(targetLocale, shared.assign({}, format, overrides));
|
|
777
|
+
__datetimeFormatters.set(id, formatter);
|
|
778
|
+
}
|
|
779
|
+
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
780
|
+
}
|
|
781
|
+
/** @internal */
|
|
782
|
+
function parseDateTimeArgs(...args) {
|
|
783
|
+
const [arg1, arg2, arg3, arg4] = args;
|
|
784
|
+
let options = {};
|
|
785
|
+
let overrides = {};
|
|
786
|
+
let value;
|
|
787
|
+
if (shared.isString(arg1)) {
|
|
788
|
+
// Only allow ISO strings - other date formats are often supported,
|
|
789
|
+
// but may cause different results in different browsers.
|
|
790
|
+
if (!/\d{4}-\d{2}-\d{2}(T.*)?/.test(arg1)) {
|
|
791
|
+
throw createCoreError(16 /* INVALID_ISO_DATE_ARGUMENT */);
|
|
792
|
+
}
|
|
793
|
+
value = new Date(arg1);
|
|
794
|
+
try {
|
|
795
|
+
// This will fail if the date is not valid
|
|
796
|
+
value.toISOString();
|
|
797
|
+
}
|
|
798
|
+
catch (e) {
|
|
799
|
+
throw createCoreError(16 /* INVALID_ISO_DATE_ARGUMENT */);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
else if (shared.isDate(arg1)) {
|
|
803
|
+
if (isNaN(arg1.getTime())) {
|
|
804
|
+
throw createCoreError(15 /* INVALID_DATE_ARGUMENT */);
|
|
805
|
+
}
|
|
806
|
+
value = arg1;
|
|
807
|
+
}
|
|
808
|
+
else if (shared.isNumber(arg1)) {
|
|
809
|
+
value = arg1;
|
|
810
|
+
}
|
|
811
|
+
else {
|
|
812
|
+
throw createCoreError(14 /* INVALID_ARGUMENT */);
|
|
813
|
+
}
|
|
814
|
+
if (shared.isString(arg2)) {
|
|
815
|
+
options.key = arg2;
|
|
816
|
+
}
|
|
817
|
+
else if (shared.isPlainObject(arg2)) {
|
|
818
|
+
options = arg2;
|
|
819
|
+
}
|
|
820
|
+
if (shared.isString(arg3)) {
|
|
821
|
+
options.locale = arg3;
|
|
822
|
+
}
|
|
823
|
+
else if (shared.isPlainObject(arg3)) {
|
|
824
|
+
overrides = arg3;
|
|
825
|
+
}
|
|
826
|
+
if (shared.isPlainObject(arg4)) {
|
|
827
|
+
overrides = arg4;
|
|
828
|
+
}
|
|
829
|
+
return [options.key || '', value, options, overrides];
|
|
830
|
+
}
|
|
831
|
+
/** @internal */
|
|
832
|
+
function clearDateTimeFormat(ctx, locale, format) {
|
|
833
|
+
const context = ctx;
|
|
834
|
+
for (const key in format) {
|
|
835
|
+
const id = `${locale}__${key}`;
|
|
836
|
+
if (!context.__datetimeFormatters.has(id)) {
|
|
837
|
+
continue;
|
|
838
|
+
}
|
|
839
|
+
context.__datetimeFormatters.delete(id);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
// implementation of `number` function
|
|
844
|
+
function number(context, ...args) {
|
|
845
|
+
const { numberFormats, unresolving, fallbackLocale, onWarn } = context;
|
|
846
|
+
const { __numberFormatters } = context;
|
|
847
|
+
if (!Availabilities.numberFormat) {
|
|
848
|
+
onWarn(getWarnMessage(2 /* CANNOT_FORMAT_NUMBER */));
|
|
849
|
+
return MISSING_RESOLVE_VALUE;
|
|
850
|
+
}
|
|
851
|
+
const [key, value, options, overrides] = parseNumberArgs(...args);
|
|
852
|
+
const missingWarn = shared.isBoolean(options.missingWarn)
|
|
853
|
+
? options.missingWarn
|
|
854
|
+
: context.missingWarn;
|
|
855
|
+
const fallbackWarn = shared.isBoolean(options.fallbackWarn)
|
|
856
|
+
? options.fallbackWarn
|
|
857
|
+
: context.fallbackWarn;
|
|
858
|
+
const part = !!options.part;
|
|
859
|
+
const locale = shared.isString(options.locale) ? options.locale : context.locale;
|
|
860
|
+
const locales = getLocaleChain(context, fallbackLocale, locale);
|
|
861
|
+
if (!shared.isString(key) || key === '') {
|
|
862
|
+
return new Intl.NumberFormat(locale).format(value);
|
|
863
|
+
}
|
|
864
|
+
// resolve format
|
|
865
|
+
let numberFormat = {};
|
|
866
|
+
let targetLocale;
|
|
867
|
+
let format = null;
|
|
868
|
+
let from = locale;
|
|
869
|
+
let to = null;
|
|
870
|
+
const type = 'number format';
|
|
871
|
+
for (let i = 0; i < locales.length; i++) {
|
|
872
|
+
targetLocale = to = locales[i];
|
|
873
|
+
if (locale !== targetLocale &&
|
|
874
|
+
isTranslateFallbackWarn(fallbackWarn, key)) {
|
|
875
|
+
onWarn(getWarnMessage(3 /* FALLBACK_TO_NUMBER_FORMAT */, {
|
|
876
|
+
key,
|
|
877
|
+
target: targetLocale
|
|
878
|
+
}));
|
|
879
|
+
}
|
|
880
|
+
// for vue-devtools timeline event
|
|
881
|
+
if (locale !== targetLocale) {
|
|
882
|
+
const emitter = context.__v_emitter;
|
|
883
|
+
if (emitter) {
|
|
884
|
+
emitter.emit("fallback" /* FALBACK */, {
|
|
885
|
+
type,
|
|
886
|
+
key,
|
|
887
|
+
from,
|
|
888
|
+
to,
|
|
889
|
+
groupId: `${type}:${key}`
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
numberFormat =
|
|
894
|
+
numberFormats[targetLocale] || {};
|
|
895
|
+
format = numberFormat[key];
|
|
896
|
+
if (shared.isPlainObject(format))
|
|
897
|
+
break;
|
|
898
|
+
handleMissing(context, key, targetLocale, missingWarn, type);
|
|
899
|
+
from = to;
|
|
900
|
+
}
|
|
901
|
+
// checking format and target locale
|
|
902
|
+
if (!shared.isPlainObject(format) || !shared.isString(targetLocale)) {
|
|
903
|
+
return unresolving ? NOT_REOSLVED : key;
|
|
904
|
+
}
|
|
905
|
+
let id = `${targetLocale}__${key}`;
|
|
906
|
+
if (!shared.isEmptyObject(overrides)) {
|
|
907
|
+
id = `${id}__${JSON.stringify(overrides)}`;
|
|
908
|
+
}
|
|
909
|
+
let formatter = __numberFormatters.get(id);
|
|
910
|
+
if (!formatter) {
|
|
911
|
+
formatter = new Intl.NumberFormat(targetLocale, shared.assign({}, format, overrides));
|
|
912
|
+
__numberFormatters.set(id, formatter);
|
|
913
|
+
}
|
|
914
|
+
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
915
|
+
}
|
|
916
|
+
/** @internal */
|
|
917
|
+
function parseNumberArgs(...args) {
|
|
918
|
+
const [arg1, arg2, arg3, arg4] = args;
|
|
919
|
+
let options = {};
|
|
920
|
+
let overrides = {};
|
|
921
|
+
if (!shared.isNumber(arg1)) {
|
|
922
|
+
throw createCoreError(14 /* INVALID_ARGUMENT */);
|
|
923
|
+
}
|
|
924
|
+
const value = arg1;
|
|
925
|
+
if (shared.isString(arg2)) {
|
|
926
|
+
options.key = arg2;
|
|
927
|
+
}
|
|
928
|
+
else if (shared.isPlainObject(arg2)) {
|
|
929
|
+
options = arg2;
|
|
930
|
+
}
|
|
931
|
+
if (shared.isString(arg3)) {
|
|
932
|
+
options.locale = arg3;
|
|
933
|
+
}
|
|
934
|
+
else if (shared.isPlainObject(arg3)) {
|
|
935
|
+
overrides = arg3;
|
|
936
|
+
}
|
|
937
|
+
if (shared.isPlainObject(arg4)) {
|
|
938
|
+
overrides = arg4;
|
|
939
|
+
}
|
|
940
|
+
return [options.key || '', value, options, overrides];
|
|
941
|
+
}
|
|
942
|
+
/** @internal */
|
|
943
|
+
function clearNumberFormat(ctx, locale, format) {
|
|
944
|
+
const context = ctx;
|
|
945
|
+
for (const key in format) {
|
|
946
|
+
const id = `${locale}__${key}`;
|
|
947
|
+
if (!context.__numberFormatters.has(id)) {
|
|
948
|
+
continue;
|
|
949
|
+
}
|
|
950
|
+
context.__numberFormatters.delete(id);
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
exports.createCompileError = messageCompiler.createCompileError;
|
|
955
|
+
exports.MISSING_RESOLVE_VALUE = MISSING_RESOLVE_VALUE;
|
|
956
|
+
exports.NOT_REOSLVED = NOT_REOSLVED;
|
|
957
|
+
exports.VERSION = VERSION;
|
|
958
|
+
exports.clearCompileCache = clearCompileCache;
|
|
959
|
+
exports.clearDateTimeFormat = clearDateTimeFormat;
|
|
960
|
+
exports.clearNumberFormat = clearNumberFormat;
|
|
961
|
+
exports.compileToFunction = compileToFunction;
|
|
962
|
+
exports.createCoreContext = createCoreContext;
|
|
963
|
+
exports.createCoreError = createCoreError;
|
|
964
|
+
exports.datetime = datetime;
|
|
965
|
+
exports.getAdditionalMeta = getAdditionalMeta;
|
|
966
|
+
exports.getDevToolsHook = getDevToolsHook;
|
|
967
|
+
exports.getLocaleChain = getLocaleChain;
|
|
968
|
+
exports.getWarnMessage = getWarnMessage;
|
|
969
|
+
exports.handleMissing = handleMissing;
|
|
970
|
+
exports.initI18nDevTools = initI18nDevTools;
|
|
971
|
+
exports.isMessageFunction = isMessageFunction;
|
|
972
|
+
exports.isTranslateFallbackWarn = isTranslateFallbackWarn;
|
|
973
|
+
exports.isTranslateMissingWarn = isTranslateMissingWarn;
|
|
974
|
+
exports.number = number;
|
|
975
|
+
exports.parseDateTimeArgs = parseDateTimeArgs;
|
|
976
|
+
exports.parseNumberArgs = parseNumberArgs;
|
|
977
|
+
exports.parseTranslateArgs = parseTranslateArgs;
|
|
978
|
+
exports.registerMessageCompiler = registerMessageCompiler;
|
|
979
|
+
exports.setAdditionalMeta = setAdditionalMeta;
|
|
980
|
+
exports.setDevToolsHook = setDevToolsHook;
|
|
981
|
+
exports.translate = translate;
|
|
982
|
+
exports.translateDevTools = translateDevTools;
|
|
983
|
+
exports.updateFallbackLocale = updateFallbackLocale;
|
|
984
|
+
Object.keys(messageResolver).forEach(function (k) {
|
|
985
|
+
if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = messageResolver[k];
|
|
986
|
+
});
|
|
987
|
+
Object.keys(runtime).forEach(function (k) {
|
|
988
|
+
if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = runtime[k];
|
|
989
|
+
});
|