@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,2224 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* vue-i18n v9.1.7
|
|
3
|
+
* (c) 2021 kazuya kawaguchi
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
import { getGlobalThis, format, makeSymbol, isPlainObject, isArray, hasOwn, isObject, isBoolean, isString, isRegExp, isFunction, assign, isNumber, warn, createEmitter, isEmptyObject } from '@intlify/shared';
|
|
7
|
+
import { createCompileError, handleFlatJson, createCoreContext, updateFallbackLocale, resolveValue, clearDateTimeFormat, clearNumberFormat, setAdditionalMeta, NOT_REOSLVED, isTranslateFallbackWarn, isTranslateMissingWarn, parseTranslateArgs, translate, MISSING_RESOLVE_VALUE, parseDateTimeArgs, datetime, parseNumberArgs, number, getLocaleChain, setDevToolsHook } from '@intlify/core-base';
|
|
8
|
+
import { ref, getCurrentInstance, computed, watch, createVNode, Text, h, Fragment, inject, onMounted, onUnmounted, isRef } from 'vue';
|
|
9
|
+
import { setupDevtoolsPlugin } from '@vue/devtools-api';
|
|
10
|
+
import { VueDevToolsLabels, VueDevToolsPlaceholders, VueDevToolsTimelineColors } from '@intlify/vue-devtools';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Vue I18n Version
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* Semver format. Same format as the package.json `version` field.
|
|
17
|
+
*
|
|
18
|
+
* @VueI18nGeneral
|
|
19
|
+
*/
|
|
20
|
+
const VERSION = '9.1.7';
|
|
21
|
+
/**
|
|
22
|
+
* This is only called in esm-bundler builds.
|
|
23
|
+
* istanbul-ignore-next
|
|
24
|
+
*/
|
|
25
|
+
function initFeatureFlags() {
|
|
26
|
+
let needWarn = false;
|
|
27
|
+
if (typeof __VUE_I18N_FULL_INSTALL__ !== 'boolean') {
|
|
28
|
+
needWarn = true;
|
|
29
|
+
getGlobalThis().__VUE_I18N_FULL_INSTALL__ = true;
|
|
30
|
+
}
|
|
31
|
+
if (typeof __VUE_I18N_LEGACY_API__ !== 'boolean') {
|
|
32
|
+
needWarn = true;
|
|
33
|
+
getGlobalThis().__VUE_I18N_LEGACY_API__ = true;
|
|
34
|
+
}
|
|
35
|
+
if (typeof __VUE_I18N_PROD_DEVTOOLS__ !== 'boolean') {
|
|
36
|
+
needWarn = true;
|
|
37
|
+
getGlobalThis().__VUE_I18N_PROD_DEVTOOLS__ = false;
|
|
38
|
+
}
|
|
39
|
+
if (typeof __INTLIFY_PROD_DEVTOOLS__ !== 'boolean') {
|
|
40
|
+
getGlobalThis().__INTLIFY_PROD_DEVTOOLS__ = false;
|
|
41
|
+
}
|
|
42
|
+
if ((process.env.NODE_ENV !== 'production') && typeof true === 'boolean') {
|
|
43
|
+
needWarn = true;
|
|
44
|
+
}
|
|
45
|
+
if ((process.env.NODE_ENV !== 'production') && needWarn) {
|
|
46
|
+
console.warn(`You are running the esm-bundler build of vue-i18n. It is recommended to ` +
|
|
47
|
+
`configure your bundler to explicitly replace feature flag globals ` +
|
|
48
|
+
`with boolean literals to get proper tree-shaking in the final bundle.`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const warnMessages = {
|
|
53
|
+
[6 /* FALLBACK_TO_ROOT */]: `Fall back to {type} '{key}' with root locale.`,
|
|
54
|
+
[7 /* NOT_SUPPORTED_PRESERVE */]: `Not supported 'preserve'.`,
|
|
55
|
+
[8 /* NOT_SUPPORTED_FORMATTER */]: `Not supported 'formatter'.`,
|
|
56
|
+
[9 /* NOT_SUPPORTED_PRESERVE_DIRECTIVE */]: `Not supported 'preserveDirectiveContent'.`,
|
|
57
|
+
[10 /* NOT_SUPPORTED_GET_CHOICE_INDEX */]: `Not supported 'getChoiceIndex'.`,
|
|
58
|
+
[11 /* COMPONENT_NAME_LEGACY_COMPATIBLE */]: `Component name legacy compatible: '{name}' -> 'i18n'`,
|
|
59
|
+
[12 /* NOT_FOUND_PARENT_SCOPE */]: `Not found parent scope. use the global scope.`
|
|
60
|
+
};
|
|
61
|
+
function getWarnMessage(code, ...args) {
|
|
62
|
+
return format(warnMessages[code], ...args);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function createI18nError(code, ...args) {
|
|
66
|
+
return createCompileError(code, null, (process.env.NODE_ENV !== 'production') ? { messages: errorMessages, args } : undefined);
|
|
67
|
+
}
|
|
68
|
+
const errorMessages = {
|
|
69
|
+
[14 /* UNEXPECTED_RETURN_TYPE */]: 'Unexpected return type in composer',
|
|
70
|
+
[15 /* INVALID_ARGUMENT */]: 'Invalid argument',
|
|
71
|
+
[16 /* MUST_BE_CALL_SETUP_TOP */]: 'Must be called at the top of a `setup` function',
|
|
72
|
+
[17 /* NOT_INSLALLED */]: 'Need to install with `app.use` function',
|
|
73
|
+
[22 /* UNEXPECTED_ERROR */]: 'Unexpected error',
|
|
74
|
+
[18 /* NOT_AVAILABLE_IN_LEGACY_MODE */]: 'Not available in legacy mode',
|
|
75
|
+
[19 /* REQUIRED_VALUE */]: `Required in value: {0}`,
|
|
76
|
+
[20 /* INVALID_VALUE */]: `Invalid value`,
|
|
77
|
+
[21 /* CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN */]: `Cannot setup vue-devtools plugin`
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const DEVTOOLS_META = '__INTLIFY_META__';
|
|
81
|
+
const TransrateVNodeSymbol = makeSymbol('__transrateVNode');
|
|
82
|
+
const DatetimePartsSymbol = makeSymbol('__datetimeParts');
|
|
83
|
+
const NumberPartsSymbol = makeSymbol('__numberParts');
|
|
84
|
+
const EnableEmitter = makeSymbol('__enableEmitter');
|
|
85
|
+
const DisableEmitter = makeSymbol('__disableEmitter');
|
|
86
|
+
const SetPluralRulesSymbol = makeSymbol('__setPluralRules');
|
|
87
|
+
makeSymbol('__intlifyMeta');
|
|
88
|
+
let composerID = 0;
|
|
89
|
+
function defineCoreMissingHandler(missing) {
|
|
90
|
+
return ((ctx, locale, key, type) => {
|
|
91
|
+
return missing(locale, key, getCurrentInstance() || undefined, type);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
function getLocaleMessages(locale, options) {
|
|
95
|
+
const { messages, __i18n } = options;
|
|
96
|
+
// prettier-ignore
|
|
97
|
+
const ret = isPlainObject(messages)
|
|
98
|
+
? messages
|
|
99
|
+
: isArray(__i18n)
|
|
100
|
+
? {}
|
|
101
|
+
: { [locale]: {} };
|
|
102
|
+
// merge locale messages of i18n custom block
|
|
103
|
+
if (isArray(__i18n)) {
|
|
104
|
+
__i18n.forEach(({ locale, resource }) => {
|
|
105
|
+
if (locale) {
|
|
106
|
+
ret[locale] = ret[locale] || {};
|
|
107
|
+
deepCopy(resource, ret[locale]);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
deepCopy(resource, ret);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
// handle messages for flat json
|
|
115
|
+
if (options.flatJson) {
|
|
116
|
+
for (const key in ret) {
|
|
117
|
+
if (hasOwn(ret, key)) {
|
|
118
|
+
handleFlatJson(ret[key]);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return ret;
|
|
123
|
+
}
|
|
124
|
+
const isNotObjectOrIsArray = (val) => !isObject(val) || isArray(val);
|
|
125
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
126
|
+
function deepCopy(src, des) {
|
|
127
|
+
// src and des should both be objects, and non of then can be a array
|
|
128
|
+
if (isNotObjectOrIsArray(src) || isNotObjectOrIsArray(des)) {
|
|
129
|
+
throw createI18nError(20 /* INVALID_VALUE */);
|
|
130
|
+
}
|
|
131
|
+
for (const key in src) {
|
|
132
|
+
if (hasOwn(src, key)) {
|
|
133
|
+
if (isNotObjectOrIsArray(src[key]) || isNotObjectOrIsArray(des[key])) {
|
|
134
|
+
// replace with src[key] when:
|
|
135
|
+
// src[key] or des[key] is not a object, or
|
|
136
|
+
// src[key] or des[key] is a array
|
|
137
|
+
des[key] = src[key];
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
// src[key] and des[key] are both object, merge them
|
|
141
|
+
deepCopy(src[key], des[key]);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// for Intlify DevTools
|
|
147
|
+
const getMetaInfo = /* #__PURE__*/ () => {
|
|
148
|
+
const instance = getCurrentInstance();
|
|
149
|
+
return instance && instance.type[DEVTOOLS_META] // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
150
|
+
? { [DEVTOOLS_META]: instance.type[DEVTOOLS_META] } // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
151
|
+
: null;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Create composer interface factory
|
|
155
|
+
*
|
|
156
|
+
* @internal
|
|
157
|
+
*/
|
|
158
|
+
function createComposer(options = {}) {
|
|
159
|
+
const { __root } = options;
|
|
160
|
+
const _isGlobal = __root === undefined;
|
|
161
|
+
let _inheritLocale = isBoolean(options.inheritLocale)
|
|
162
|
+
? options.inheritLocale
|
|
163
|
+
: true;
|
|
164
|
+
const _locale = ref(
|
|
165
|
+
// prettier-ignore
|
|
166
|
+
__root && _inheritLocale
|
|
167
|
+
? __root.locale.value
|
|
168
|
+
: isString(options.locale)
|
|
169
|
+
? options.locale
|
|
170
|
+
: 'en-US');
|
|
171
|
+
const _fallbackLocale = ref(
|
|
172
|
+
// prettier-ignore
|
|
173
|
+
__root && _inheritLocale
|
|
174
|
+
? __root.fallbackLocale.value
|
|
175
|
+
: isString(options.fallbackLocale) ||
|
|
176
|
+
isArray(options.fallbackLocale) ||
|
|
177
|
+
isPlainObject(options.fallbackLocale) ||
|
|
178
|
+
options.fallbackLocale === false
|
|
179
|
+
? options.fallbackLocale
|
|
180
|
+
: _locale.value);
|
|
181
|
+
const _messages = ref(getLocaleMessages(_locale.value, options));
|
|
182
|
+
const _datetimeFormats = ref(isPlainObject(options.datetimeFormats)
|
|
183
|
+
? options.datetimeFormats
|
|
184
|
+
: { [_locale.value]: {} });
|
|
185
|
+
const _numberFormats = ref(isPlainObject(options.numberFormats)
|
|
186
|
+
? options.numberFormats
|
|
187
|
+
: { [_locale.value]: {} });
|
|
188
|
+
// warning suppress options
|
|
189
|
+
// prettier-ignore
|
|
190
|
+
let _missingWarn = __root
|
|
191
|
+
? __root.missingWarn
|
|
192
|
+
: isBoolean(options.missingWarn) || isRegExp(options.missingWarn)
|
|
193
|
+
? options.missingWarn
|
|
194
|
+
: true;
|
|
195
|
+
// prettier-ignore
|
|
196
|
+
let _fallbackWarn = __root
|
|
197
|
+
? __root.fallbackWarn
|
|
198
|
+
: isBoolean(options.fallbackWarn) || isRegExp(options.fallbackWarn)
|
|
199
|
+
? options.fallbackWarn
|
|
200
|
+
: true;
|
|
201
|
+
// prettier-ignore
|
|
202
|
+
let _fallbackRoot = __root
|
|
203
|
+
? __root.fallbackRoot
|
|
204
|
+
: isBoolean(options.fallbackRoot)
|
|
205
|
+
? options.fallbackRoot
|
|
206
|
+
: true;
|
|
207
|
+
// configure fall back to root
|
|
208
|
+
let _fallbackFormat = !!options.fallbackFormat;
|
|
209
|
+
// runtime missing
|
|
210
|
+
let _missing = isFunction(options.missing) ? options.missing : null;
|
|
211
|
+
let _runtimeMissing = isFunction(options.missing)
|
|
212
|
+
? defineCoreMissingHandler(options.missing)
|
|
213
|
+
: null;
|
|
214
|
+
// postTranslation handler
|
|
215
|
+
let _postTranslation = isFunction(options.postTranslation)
|
|
216
|
+
? options.postTranslation
|
|
217
|
+
: null;
|
|
218
|
+
let _warnHtmlMessage = isBoolean(options.warnHtmlMessage)
|
|
219
|
+
? options.warnHtmlMessage
|
|
220
|
+
: true;
|
|
221
|
+
let _escapeParameter = !!options.escapeParameter;
|
|
222
|
+
// custom linked modifiers
|
|
223
|
+
// prettier-ignore
|
|
224
|
+
const _modifiers = __root
|
|
225
|
+
? __root.modifiers
|
|
226
|
+
: isPlainObject(options.modifiers)
|
|
227
|
+
? options.modifiers
|
|
228
|
+
: {};
|
|
229
|
+
// pluralRules
|
|
230
|
+
let _pluralRules = options.pluralRules || (__root && __root.pluralRules);
|
|
231
|
+
// runtime context
|
|
232
|
+
// eslint-disable-next-line prefer-const
|
|
233
|
+
let _context;
|
|
234
|
+
function getCoreContext() {
|
|
235
|
+
return createCoreContext({
|
|
236
|
+
version: VERSION,
|
|
237
|
+
locale: _locale.value,
|
|
238
|
+
fallbackLocale: _fallbackLocale.value,
|
|
239
|
+
messages: _messages.value,
|
|
240
|
+
datetimeFormats: _datetimeFormats.value,
|
|
241
|
+
numberFormats: _numberFormats.value,
|
|
242
|
+
modifiers: _modifiers,
|
|
243
|
+
pluralRules: _pluralRules,
|
|
244
|
+
missing: _runtimeMissing === null ? undefined : _runtimeMissing,
|
|
245
|
+
missingWarn: _missingWarn,
|
|
246
|
+
fallbackWarn: _fallbackWarn,
|
|
247
|
+
fallbackFormat: _fallbackFormat,
|
|
248
|
+
unresolving: true,
|
|
249
|
+
postTranslation: _postTranslation === null ? undefined : _postTranslation,
|
|
250
|
+
warnHtmlMessage: _warnHtmlMessage,
|
|
251
|
+
escapeParameter: _escapeParameter,
|
|
252
|
+
__datetimeFormatters: isPlainObject(_context)
|
|
253
|
+
? _context.__datetimeFormatters
|
|
254
|
+
: undefined,
|
|
255
|
+
__numberFormatters: isPlainObject(_context)
|
|
256
|
+
? _context.__numberFormatters
|
|
257
|
+
: undefined,
|
|
258
|
+
__v_emitter: isPlainObject(_context)
|
|
259
|
+
? _context.__v_emitter
|
|
260
|
+
: undefined,
|
|
261
|
+
__meta: { framework: 'vue' }
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
_context = getCoreContext();
|
|
265
|
+
updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
|
|
266
|
+
// track reactivity
|
|
267
|
+
function trackReactivityValues() {
|
|
268
|
+
return [
|
|
269
|
+
_locale.value,
|
|
270
|
+
_fallbackLocale.value,
|
|
271
|
+
_messages.value,
|
|
272
|
+
_datetimeFormats.value,
|
|
273
|
+
_numberFormats.value
|
|
274
|
+
];
|
|
275
|
+
}
|
|
276
|
+
// locale
|
|
277
|
+
const locale = computed({
|
|
278
|
+
get: () => _locale.value,
|
|
279
|
+
set: val => {
|
|
280
|
+
_locale.value = val;
|
|
281
|
+
_context.locale = _locale.value;
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
// fallbackLocale
|
|
285
|
+
const fallbackLocale = computed({
|
|
286
|
+
get: () => _fallbackLocale.value,
|
|
287
|
+
set: val => {
|
|
288
|
+
_fallbackLocale.value = val;
|
|
289
|
+
_context.fallbackLocale = _fallbackLocale.value;
|
|
290
|
+
updateFallbackLocale(_context, _locale.value, val);
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
// messages
|
|
294
|
+
const messages = computed(() => _messages.value);
|
|
295
|
+
// datetimeFormats
|
|
296
|
+
const datetimeFormats = computed(() => _datetimeFormats.value);
|
|
297
|
+
// numberFormats
|
|
298
|
+
const numberFormats = computed(() => _numberFormats.value);
|
|
299
|
+
// getPostTranslationHandler
|
|
300
|
+
function getPostTranslationHandler() {
|
|
301
|
+
return isFunction(_postTranslation) ? _postTranslation : null;
|
|
302
|
+
}
|
|
303
|
+
// setPostTranslationHandler
|
|
304
|
+
function setPostTranslationHandler(handler) {
|
|
305
|
+
_postTranslation = handler;
|
|
306
|
+
_context.postTranslation = handler;
|
|
307
|
+
}
|
|
308
|
+
// getMissingHandler
|
|
309
|
+
function getMissingHandler() {
|
|
310
|
+
return _missing;
|
|
311
|
+
}
|
|
312
|
+
// setMissingHandler
|
|
313
|
+
function setMissingHandler(handler) {
|
|
314
|
+
if (handler !== null) {
|
|
315
|
+
_runtimeMissing = defineCoreMissingHandler(handler);
|
|
316
|
+
}
|
|
317
|
+
_missing = handler;
|
|
318
|
+
_context.missing = _runtimeMissing;
|
|
319
|
+
}
|
|
320
|
+
function isResolvedTranslateMessage(type, arg // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
321
|
+
) {
|
|
322
|
+
return type !== 'translate' || !!arg.resolvedMessage === false;
|
|
323
|
+
}
|
|
324
|
+
function wrapWithDeps(fn, argumentParser, warnType, fallbackSuccess, fallbackFail, successCondition) {
|
|
325
|
+
trackReactivityValues(); // track reactive dependency
|
|
326
|
+
// NOTE: experimental !!
|
|
327
|
+
let ret;
|
|
328
|
+
if ((process.env.NODE_ENV !== 'production') || __INTLIFY_PROD_DEVTOOLS__) {
|
|
329
|
+
try {
|
|
330
|
+
setAdditionalMeta(getMetaInfo());
|
|
331
|
+
ret = fn(_context);
|
|
332
|
+
}
|
|
333
|
+
finally {
|
|
334
|
+
setAdditionalMeta(null);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
ret = fn(_context);
|
|
339
|
+
}
|
|
340
|
+
if (isNumber(ret) && ret === NOT_REOSLVED) {
|
|
341
|
+
const [key, arg2] = argumentParser();
|
|
342
|
+
if ((process.env.NODE_ENV !== 'production') &&
|
|
343
|
+
__root &&
|
|
344
|
+
isString(key) &&
|
|
345
|
+
isResolvedTranslateMessage(warnType, arg2)) {
|
|
346
|
+
if (_fallbackRoot &&
|
|
347
|
+
(isTranslateFallbackWarn(_fallbackWarn, key) ||
|
|
348
|
+
isTranslateMissingWarn(_missingWarn, key))) {
|
|
349
|
+
warn(getWarnMessage(6 /* FALLBACK_TO_ROOT */, {
|
|
350
|
+
key,
|
|
351
|
+
type: warnType
|
|
352
|
+
}));
|
|
353
|
+
}
|
|
354
|
+
// for vue-devtools timeline event
|
|
355
|
+
if ((process.env.NODE_ENV !== 'production')) {
|
|
356
|
+
const { __v_emitter: emitter } = _context;
|
|
357
|
+
if (emitter && _fallbackRoot) {
|
|
358
|
+
emitter.emit("fallback" /* FALBACK */, {
|
|
359
|
+
type: warnType,
|
|
360
|
+
key,
|
|
361
|
+
to: 'global',
|
|
362
|
+
groupId: `${warnType}:${key}`
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return __root && _fallbackRoot
|
|
368
|
+
? fallbackSuccess(__root)
|
|
369
|
+
: fallbackFail(key);
|
|
370
|
+
}
|
|
371
|
+
else if (successCondition(ret)) {
|
|
372
|
+
return ret;
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
/* istanbul ignore next */
|
|
376
|
+
throw createI18nError(14 /* UNEXPECTED_RETURN_TYPE */);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
// t
|
|
380
|
+
function t(...args) {
|
|
381
|
+
return wrapWithDeps(context => translate(context, ...args), () => parseTranslateArgs(...args), 'translate', root => root.t(...args), key => key, val => isString(val));
|
|
382
|
+
}
|
|
383
|
+
// rt
|
|
384
|
+
function rt(...args) {
|
|
385
|
+
const [arg1, arg2, arg3] = args;
|
|
386
|
+
if (arg3 && !isObject(arg3)) {
|
|
387
|
+
throw createI18nError(15 /* INVALID_ARGUMENT */);
|
|
388
|
+
}
|
|
389
|
+
return t(...[arg1, arg2, assign({ resolvedMessage: true }, arg3 || {})]);
|
|
390
|
+
}
|
|
391
|
+
// d
|
|
392
|
+
function d(...args) {
|
|
393
|
+
return wrapWithDeps(context => datetime(context, ...args), () => parseDateTimeArgs(...args), 'datetime format', root => root.d(...args), () => MISSING_RESOLVE_VALUE, val => isString(val));
|
|
394
|
+
}
|
|
395
|
+
// n
|
|
396
|
+
function n(...args) {
|
|
397
|
+
return wrapWithDeps(context => number(context, ...args), () => parseNumberArgs(...args), 'number format', root => root.n(...args), () => MISSING_RESOLVE_VALUE, val => isString(val));
|
|
398
|
+
}
|
|
399
|
+
// for custom processor
|
|
400
|
+
function normalize(values) {
|
|
401
|
+
return values.map(val => isString(val) ? createVNode(Text, null, val, 0) : val);
|
|
402
|
+
}
|
|
403
|
+
const interpolate = (val) => val;
|
|
404
|
+
const processor = {
|
|
405
|
+
normalize,
|
|
406
|
+
interpolate,
|
|
407
|
+
type: 'vnode'
|
|
408
|
+
};
|
|
409
|
+
// transrateVNode, using for `i18n-t` component
|
|
410
|
+
function transrateVNode(...args) {
|
|
411
|
+
return wrapWithDeps(context => {
|
|
412
|
+
let ret;
|
|
413
|
+
const _context = context;
|
|
414
|
+
try {
|
|
415
|
+
_context.processor = processor;
|
|
416
|
+
ret = translate(_context, ...args);
|
|
417
|
+
}
|
|
418
|
+
finally {
|
|
419
|
+
_context.processor = null;
|
|
420
|
+
}
|
|
421
|
+
return ret;
|
|
422
|
+
}, () => parseTranslateArgs(...args), 'translate',
|
|
423
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
424
|
+
root => root[TransrateVNodeSymbol](...args), key => [createVNode(Text, null, key, 0)], val => isArray(val));
|
|
425
|
+
}
|
|
426
|
+
// numberParts, using for `i18n-n` component
|
|
427
|
+
function numberParts(...args) {
|
|
428
|
+
return wrapWithDeps(context => number(context, ...args), () => parseNumberArgs(...args), 'number format',
|
|
429
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
430
|
+
root => root[NumberPartsSymbol](...args), () => [], val => isString(val) || isArray(val));
|
|
431
|
+
}
|
|
432
|
+
// datetimeParts, using for `i18n-d` component
|
|
433
|
+
function datetimeParts(...args) {
|
|
434
|
+
return wrapWithDeps(context => datetime(context, ...args), () => parseDateTimeArgs(...args), 'datetime format',
|
|
435
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
436
|
+
root => root[DatetimePartsSymbol](...args), () => [], val => isString(val) || isArray(val));
|
|
437
|
+
}
|
|
438
|
+
function setPluralRules(rules) {
|
|
439
|
+
_pluralRules = rules;
|
|
440
|
+
_context.pluralRules = _pluralRules;
|
|
441
|
+
}
|
|
442
|
+
// te
|
|
443
|
+
function te(key, locale) {
|
|
444
|
+
const targetLocale = isString(locale) ? locale : _locale.value;
|
|
445
|
+
const message = getLocaleMessage(targetLocale);
|
|
446
|
+
return resolveValue(message, key) !== null;
|
|
447
|
+
}
|
|
448
|
+
function resolveMessages(key) {
|
|
449
|
+
let messages = null;
|
|
450
|
+
const locales = getLocaleChain(_context, _fallbackLocale.value, _locale.value);
|
|
451
|
+
for (let i = 0; i < locales.length; i++) {
|
|
452
|
+
const targetLocaleMessages = _messages.value[locales[i]] || {};
|
|
453
|
+
const messageValue = resolveValue(targetLocaleMessages, key);
|
|
454
|
+
if (messageValue != null) {
|
|
455
|
+
messages = messageValue;
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return messages;
|
|
460
|
+
}
|
|
461
|
+
// tm
|
|
462
|
+
function tm(key) {
|
|
463
|
+
const messages = resolveMessages(key);
|
|
464
|
+
// prettier-ignore
|
|
465
|
+
return messages != null
|
|
466
|
+
? messages
|
|
467
|
+
: __root
|
|
468
|
+
? __root.tm(key) || {}
|
|
469
|
+
: {};
|
|
470
|
+
}
|
|
471
|
+
// getLocaleMessage
|
|
472
|
+
function getLocaleMessage(locale) {
|
|
473
|
+
return (_messages.value[locale] || {});
|
|
474
|
+
}
|
|
475
|
+
// setLocaleMessage
|
|
476
|
+
function setLocaleMessage(locale, message) {
|
|
477
|
+
_messages.value[locale] = message;
|
|
478
|
+
_context.messages = _messages.value;
|
|
479
|
+
}
|
|
480
|
+
// mergeLocaleMessage
|
|
481
|
+
function mergeLocaleMessage(locale, message) {
|
|
482
|
+
_messages.value[locale] = _messages.value[locale] || {};
|
|
483
|
+
deepCopy(message, _messages.value[locale]);
|
|
484
|
+
_context.messages = _messages.value;
|
|
485
|
+
}
|
|
486
|
+
// getDateTimeFormat
|
|
487
|
+
function getDateTimeFormat(locale) {
|
|
488
|
+
return _datetimeFormats.value[locale] || {};
|
|
489
|
+
}
|
|
490
|
+
// setDateTimeFormat
|
|
491
|
+
function setDateTimeFormat(locale, format) {
|
|
492
|
+
_datetimeFormats.value[locale] = format;
|
|
493
|
+
_context.datetimeFormats = _datetimeFormats.value;
|
|
494
|
+
clearDateTimeFormat(_context, locale, format);
|
|
495
|
+
}
|
|
496
|
+
// mergeDateTimeFormat
|
|
497
|
+
function mergeDateTimeFormat(locale, format) {
|
|
498
|
+
_datetimeFormats.value[locale] = assign(_datetimeFormats.value[locale] || {}, format);
|
|
499
|
+
_context.datetimeFormats = _datetimeFormats.value;
|
|
500
|
+
clearDateTimeFormat(_context, locale, format);
|
|
501
|
+
}
|
|
502
|
+
// getNumberFormat
|
|
503
|
+
function getNumberFormat(locale) {
|
|
504
|
+
return _numberFormats.value[locale] || {};
|
|
505
|
+
}
|
|
506
|
+
// setNumberFormat
|
|
507
|
+
function setNumberFormat(locale, format) {
|
|
508
|
+
_numberFormats.value[locale] = format;
|
|
509
|
+
_context.numberFormats = _numberFormats.value;
|
|
510
|
+
clearNumberFormat(_context, locale, format);
|
|
511
|
+
}
|
|
512
|
+
// mergeNumberFormat
|
|
513
|
+
function mergeNumberFormat(locale, format) {
|
|
514
|
+
_numberFormats.value[locale] = assign(_numberFormats.value[locale] || {}, format);
|
|
515
|
+
_context.numberFormats = _numberFormats.value;
|
|
516
|
+
clearNumberFormat(_context, locale, format);
|
|
517
|
+
}
|
|
518
|
+
// for debug
|
|
519
|
+
composerID++;
|
|
520
|
+
// watch root locale & fallbackLocale
|
|
521
|
+
if (__root) {
|
|
522
|
+
watch(__root.locale, (val) => {
|
|
523
|
+
if (_inheritLocale) {
|
|
524
|
+
_locale.value = val;
|
|
525
|
+
_context.locale = val;
|
|
526
|
+
updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
watch(__root.fallbackLocale, (val) => {
|
|
530
|
+
if (_inheritLocale) {
|
|
531
|
+
_fallbackLocale.value = val;
|
|
532
|
+
_context.fallbackLocale = val;
|
|
533
|
+
updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
// define composition API!
|
|
538
|
+
const composer = {
|
|
539
|
+
id: composerID,
|
|
540
|
+
locale,
|
|
541
|
+
fallbackLocale,
|
|
542
|
+
get inheritLocale() {
|
|
543
|
+
return _inheritLocale;
|
|
544
|
+
},
|
|
545
|
+
set inheritLocale(val) {
|
|
546
|
+
_inheritLocale = val;
|
|
547
|
+
if (val && __root) {
|
|
548
|
+
_locale.value = __root.locale.value;
|
|
549
|
+
_fallbackLocale.value = __root.fallbackLocale.value;
|
|
550
|
+
updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
|
|
551
|
+
}
|
|
552
|
+
},
|
|
553
|
+
get availableLocales() {
|
|
554
|
+
return Object.keys(_messages.value).sort();
|
|
555
|
+
},
|
|
556
|
+
messages,
|
|
557
|
+
datetimeFormats,
|
|
558
|
+
numberFormats,
|
|
559
|
+
get modifiers() {
|
|
560
|
+
return _modifiers;
|
|
561
|
+
},
|
|
562
|
+
get pluralRules() {
|
|
563
|
+
return _pluralRules || {};
|
|
564
|
+
},
|
|
565
|
+
get isGlobal() {
|
|
566
|
+
return _isGlobal;
|
|
567
|
+
},
|
|
568
|
+
get missingWarn() {
|
|
569
|
+
return _missingWarn;
|
|
570
|
+
},
|
|
571
|
+
set missingWarn(val) {
|
|
572
|
+
_missingWarn = val;
|
|
573
|
+
_context.missingWarn = _missingWarn;
|
|
574
|
+
},
|
|
575
|
+
get fallbackWarn() {
|
|
576
|
+
return _fallbackWarn;
|
|
577
|
+
},
|
|
578
|
+
set fallbackWarn(val) {
|
|
579
|
+
_fallbackWarn = val;
|
|
580
|
+
_context.fallbackWarn = _fallbackWarn;
|
|
581
|
+
},
|
|
582
|
+
get fallbackRoot() {
|
|
583
|
+
return _fallbackRoot;
|
|
584
|
+
},
|
|
585
|
+
set fallbackRoot(val) {
|
|
586
|
+
_fallbackRoot = val;
|
|
587
|
+
},
|
|
588
|
+
get fallbackFormat() {
|
|
589
|
+
return _fallbackFormat;
|
|
590
|
+
},
|
|
591
|
+
set fallbackFormat(val) {
|
|
592
|
+
_fallbackFormat = val;
|
|
593
|
+
_context.fallbackFormat = _fallbackFormat;
|
|
594
|
+
},
|
|
595
|
+
get warnHtmlMessage() {
|
|
596
|
+
return _warnHtmlMessage;
|
|
597
|
+
},
|
|
598
|
+
set warnHtmlMessage(val) {
|
|
599
|
+
_warnHtmlMessage = val;
|
|
600
|
+
_context.warnHtmlMessage = val;
|
|
601
|
+
},
|
|
602
|
+
get escapeParameter() {
|
|
603
|
+
return _escapeParameter;
|
|
604
|
+
},
|
|
605
|
+
set escapeParameter(val) {
|
|
606
|
+
_escapeParameter = val;
|
|
607
|
+
_context.escapeParameter = val;
|
|
608
|
+
},
|
|
609
|
+
t,
|
|
610
|
+
rt,
|
|
611
|
+
d,
|
|
612
|
+
n,
|
|
613
|
+
te,
|
|
614
|
+
tm,
|
|
615
|
+
getLocaleMessage,
|
|
616
|
+
setLocaleMessage,
|
|
617
|
+
mergeLocaleMessage,
|
|
618
|
+
getDateTimeFormat,
|
|
619
|
+
setDateTimeFormat,
|
|
620
|
+
mergeDateTimeFormat,
|
|
621
|
+
getNumberFormat,
|
|
622
|
+
setNumberFormat,
|
|
623
|
+
mergeNumberFormat,
|
|
624
|
+
getPostTranslationHandler,
|
|
625
|
+
setPostTranslationHandler,
|
|
626
|
+
getMissingHandler,
|
|
627
|
+
setMissingHandler,
|
|
628
|
+
[TransrateVNodeSymbol]: transrateVNode,
|
|
629
|
+
[NumberPartsSymbol]: numberParts,
|
|
630
|
+
[DatetimePartsSymbol]: datetimeParts,
|
|
631
|
+
[SetPluralRulesSymbol]: setPluralRules
|
|
632
|
+
};
|
|
633
|
+
// for vue-devtools timeline event
|
|
634
|
+
if ((process.env.NODE_ENV !== 'production')) {
|
|
635
|
+
composer[EnableEmitter] = (emitter) => {
|
|
636
|
+
_context.__v_emitter = emitter;
|
|
637
|
+
};
|
|
638
|
+
composer[DisableEmitter] = () => {
|
|
639
|
+
_context.__v_emitter = undefined;
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
return composer;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* Convert to I18n Composer Options from VueI18n Options
|
|
647
|
+
*
|
|
648
|
+
* @internal
|
|
649
|
+
*/
|
|
650
|
+
function convertComposerOptions(options) {
|
|
651
|
+
const locale = isString(options.locale) ? options.locale : 'en-US';
|
|
652
|
+
const fallbackLocale = isString(options.fallbackLocale) ||
|
|
653
|
+
isArray(options.fallbackLocale) ||
|
|
654
|
+
isPlainObject(options.fallbackLocale) ||
|
|
655
|
+
options.fallbackLocale === false
|
|
656
|
+
? options.fallbackLocale
|
|
657
|
+
: locale;
|
|
658
|
+
const missing = isFunction(options.missing) ? options.missing : undefined;
|
|
659
|
+
const missingWarn = isBoolean(options.silentTranslationWarn) ||
|
|
660
|
+
isRegExp(options.silentTranslationWarn)
|
|
661
|
+
? !options.silentTranslationWarn
|
|
662
|
+
: true;
|
|
663
|
+
const fallbackWarn = isBoolean(options.silentFallbackWarn) ||
|
|
664
|
+
isRegExp(options.silentFallbackWarn)
|
|
665
|
+
? !options.silentFallbackWarn
|
|
666
|
+
: true;
|
|
667
|
+
const fallbackRoot = isBoolean(options.fallbackRoot)
|
|
668
|
+
? options.fallbackRoot
|
|
669
|
+
: true;
|
|
670
|
+
const fallbackFormat = !!options.formatFallbackMessages;
|
|
671
|
+
const modifiers = isPlainObject(options.modifiers) ? options.modifiers : {};
|
|
672
|
+
const pluralizationRules = options.pluralizationRules;
|
|
673
|
+
const postTranslation = isFunction(options.postTranslation)
|
|
674
|
+
? options.postTranslation
|
|
675
|
+
: undefined;
|
|
676
|
+
const warnHtmlMessage = isString(options.warnHtmlInMessage)
|
|
677
|
+
? options.warnHtmlInMessage !== 'off'
|
|
678
|
+
: true;
|
|
679
|
+
const escapeParameter = !!options.escapeParameterHtml;
|
|
680
|
+
const inheritLocale = isBoolean(options.sync) ? options.sync : true;
|
|
681
|
+
if ((process.env.NODE_ENV !== 'production') && options.formatter) {
|
|
682
|
+
warn(getWarnMessage(8 /* NOT_SUPPORTED_FORMATTER */));
|
|
683
|
+
}
|
|
684
|
+
if ((process.env.NODE_ENV !== 'production') && options.preserveDirectiveContent) {
|
|
685
|
+
warn(getWarnMessage(9 /* NOT_SUPPORTED_PRESERVE_DIRECTIVE */));
|
|
686
|
+
}
|
|
687
|
+
let messages = options.messages;
|
|
688
|
+
if (isPlainObject(options.sharedMessages)) {
|
|
689
|
+
const sharedMessages = options.sharedMessages;
|
|
690
|
+
const locales = Object.keys(sharedMessages);
|
|
691
|
+
messages = locales.reduce((messages, locale) => {
|
|
692
|
+
const message = messages[locale] || (messages[locale] = {});
|
|
693
|
+
assign(message, sharedMessages[locale]);
|
|
694
|
+
return messages;
|
|
695
|
+
}, (messages || {}));
|
|
696
|
+
}
|
|
697
|
+
const { __i18n, __root } = options;
|
|
698
|
+
const datetimeFormats = options.datetimeFormats;
|
|
699
|
+
const numberFormats = options.numberFormats;
|
|
700
|
+
const flatJson = options.flatJson;
|
|
701
|
+
return {
|
|
702
|
+
locale,
|
|
703
|
+
fallbackLocale,
|
|
704
|
+
messages,
|
|
705
|
+
flatJson,
|
|
706
|
+
datetimeFormats,
|
|
707
|
+
numberFormats,
|
|
708
|
+
missing,
|
|
709
|
+
missingWarn,
|
|
710
|
+
fallbackWarn,
|
|
711
|
+
fallbackRoot,
|
|
712
|
+
fallbackFormat,
|
|
713
|
+
modifiers,
|
|
714
|
+
pluralRules: pluralizationRules,
|
|
715
|
+
postTranslation,
|
|
716
|
+
warnHtmlMessage,
|
|
717
|
+
escapeParameter,
|
|
718
|
+
inheritLocale,
|
|
719
|
+
__i18n,
|
|
720
|
+
__root
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* create VueI18n interface factory
|
|
725
|
+
*
|
|
726
|
+
* @internal
|
|
727
|
+
*/
|
|
728
|
+
function createVueI18n(options = {}) {
|
|
729
|
+
const composer = createComposer(convertComposerOptions(options));
|
|
730
|
+
// defines VueI18n
|
|
731
|
+
const vueI18n = {
|
|
732
|
+
// id
|
|
733
|
+
id: composer.id,
|
|
734
|
+
// locale
|
|
735
|
+
get locale() {
|
|
736
|
+
return composer.locale.value;
|
|
737
|
+
},
|
|
738
|
+
set locale(val) {
|
|
739
|
+
composer.locale.value = val;
|
|
740
|
+
},
|
|
741
|
+
// fallbackLocale
|
|
742
|
+
get fallbackLocale() {
|
|
743
|
+
return composer.fallbackLocale.value;
|
|
744
|
+
},
|
|
745
|
+
set fallbackLocale(val) {
|
|
746
|
+
composer.fallbackLocale.value = val;
|
|
747
|
+
},
|
|
748
|
+
// messages
|
|
749
|
+
get messages() {
|
|
750
|
+
return composer.messages.value;
|
|
751
|
+
},
|
|
752
|
+
// datetimeFormats
|
|
753
|
+
get datetimeFormats() {
|
|
754
|
+
return composer.datetimeFormats.value;
|
|
755
|
+
},
|
|
756
|
+
// numberFormats
|
|
757
|
+
get numberFormats() {
|
|
758
|
+
return composer.numberFormats.value;
|
|
759
|
+
},
|
|
760
|
+
// availableLocales
|
|
761
|
+
get availableLocales() {
|
|
762
|
+
return composer.availableLocales;
|
|
763
|
+
},
|
|
764
|
+
// formatter
|
|
765
|
+
get formatter() {
|
|
766
|
+
(process.env.NODE_ENV !== 'production') && warn(getWarnMessage(8 /* NOT_SUPPORTED_FORMATTER */));
|
|
767
|
+
// dummy
|
|
768
|
+
return {
|
|
769
|
+
interpolate() {
|
|
770
|
+
return [];
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
},
|
|
774
|
+
set formatter(val) {
|
|
775
|
+
(process.env.NODE_ENV !== 'production') && warn(getWarnMessage(8 /* NOT_SUPPORTED_FORMATTER */));
|
|
776
|
+
},
|
|
777
|
+
// missing
|
|
778
|
+
get missing() {
|
|
779
|
+
return composer.getMissingHandler();
|
|
780
|
+
},
|
|
781
|
+
set missing(handler) {
|
|
782
|
+
composer.setMissingHandler(handler);
|
|
783
|
+
},
|
|
784
|
+
// silentTranslationWarn
|
|
785
|
+
get silentTranslationWarn() {
|
|
786
|
+
return isBoolean(composer.missingWarn)
|
|
787
|
+
? !composer.missingWarn
|
|
788
|
+
: composer.missingWarn;
|
|
789
|
+
},
|
|
790
|
+
set silentTranslationWarn(val) {
|
|
791
|
+
composer.missingWarn = isBoolean(val) ? !val : val;
|
|
792
|
+
},
|
|
793
|
+
// silentFallbackWarn
|
|
794
|
+
get silentFallbackWarn() {
|
|
795
|
+
return isBoolean(composer.fallbackWarn)
|
|
796
|
+
? !composer.fallbackWarn
|
|
797
|
+
: composer.fallbackWarn;
|
|
798
|
+
},
|
|
799
|
+
set silentFallbackWarn(val) {
|
|
800
|
+
composer.fallbackWarn = isBoolean(val) ? !val : val;
|
|
801
|
+
},
|
|
802
|
+
// modifiers
|
|
803
|
+
get modifiers() {
|
|
804
|
+
return composer.modifiers;
|
|
805
|
+
},
|
|
806
|
+
// formatFallbackMessages
|
|
807
|
+
get formatFallbackMessages() {
|
|
808
|
+
return composer.fallbackFormat;
|
|
809
|
+
},
|
|
810
|
+
set formatFallbackMessages(val) {
|
|
811
|
+
composer.fallbackFormat = val;
|
|
812
|
+
},
|
|
813
|
+
// postTranslation
|
|
814
|
+
get postTranslation() {
|
|
815
|
+
return composer.getPostTranslationHandler();
|
|
816
|
+
},
|
|
817
|
+
set postTranslation(handler) {
|
|
818
|
+
composer.setPostTranslationHandler(handler);
|
|
819
|
+
},
|
|
820
|
+
// sync
|
|
821
|
+
get sync() {
|
|
822
|
+
return composer.inheritLocale;
|
|
823
|
+
},
|
|
824
|
+
set sync(val) {
|
|
825
|
+
composer.inheritLocale = val;
|
|
826
|
+
},
|
|
827
|
+
// warnInHtmlMessage
|
|
828
|
+
get warnHtmlInMessage() {
|
|
829
|
+
return composer.warnHtmlMessage ? 'warn' : 'off';
|
|
830
|
+
},
|
|
831
|
+
set warnHtmlInMessage(val) {
|
|
832
|
+
composer.warnHtmlMessage = val !== 'off';
|
|
833
|
+
},
|
|
834
|
+
// escapeParameterHtml
|
|
835
|
+
get escapeParameterHtml() {
|
|
836
|
+
return composer.escapeParameter;
|
|
837
|
+
},
|
|
838
|
+
set escapeParameterHtml(val) {
|
|
839
|
+
composer.escapeParameter = val;
|
|
840
|
+
},
|
|
841
|
+
// preserveDirectiveContent
|
|
842
|
+
get preserveDirectiveContent() {
|
|
843
|
+
(process.env.NODE_ENV !== 'production') &&
|
|
844
|
+
warn(getWarnMessage(9 /* NOT_SUPPORTED_PRESERVE_DIRECTIVE */));
|
|
845
|
+
return true;
|
|
846
|
+
},
|
|
847
|
+
set preserveDirectiveContent(val) {
|
|
848
|
+
(process.env.NODE_ENV !== 'production') &&
|
|
849
|
+
warn(getWarnMessage(9 /* NOT_SUPPORTED_PRESERVE_DIRECTIVE */));
|
|
850
|
+
},
|
|
851
|
+
// pluralizationRules
|
|
852
|
+
get pluralizationRules() {
|
|
853
|
+
return composer.pluralRules || {};
|
|
854
|
+
},
|
|
855
|
+
// for internal
|
|
856
|
+
__composer: composer,
|
|
857
|
+
// t
|
|
858
|
+
t(...args) {
|
|
859
|
+
const [arg1, arg2, arg3] = args;
|
|
860
|
+
const options = {};
|
|
861
|
+
let list = null;
|
|
862
|
+
let named = null;
|
|
863
|
+
if (!isString(arg1)) {
|
|
864
|
+
throw createI18nError(15 /* INVALID_ARGUMENT */);
|
|
865
|
+
}
|
|
866
|
+
const key = arg1;
|
|
867
|
+
if (isString(arg2)) {
|
|
868
|
+
options.locale = arg2;
|
|
869
|
+
}
|
|
870
|
+
else if (isArray(arg2)) {
|
|
871
|
+
list = arg2;
|
|
872
|
+
}
|
|
873
|
+
else if (isPlainObject(arg2)) {
|
|
874
|
+
named = arg2;
|
|
875
|
+
}
|
|
876
|
+
if (isArray(arg3)) {
|
|
877
|
+
list = arg3;
|
|
878
|
+
}
|
|
879
|
+
else if (isPlainObject(arg3)) {
|
|
880
|
+
named = arg3;
|
|
881
|
+
}
|
|
882
|
+
return composer.t(key, list || named || {}, options);
|
|
883
|
+
},
|
|
884
|
+
rt(...args) {
|
|
885
|
+
return composer.rt(...args);
|
|
886
|
+
},
|
|
887
|
+
// tc
|
|
888
|
+
tc(...args) {
|
|
889
|
+
const [arg1, arg2, arg3] = args;
|
|
890
|
+
const options = { plural: 1 };
|
|
891
|
+
let list = null;
|
|
892
|
+
let named = null;
|
|
893
|
+
if (!isString(arg1)) {
|
|
894
|
+
throw createI18nError(15 /* INVALID_ARGUMENT */);
|
|
895
|
+
}
|
|
896
|
+
const key = arg1;
|
|
897
|
+
if (isString(arg2)) {
|
|
898
|
+
options.locale = arg2;
|
|
899
|
+
}
|
|
900
|
+
else if (isNumber(arg2)) {
|
|
901
|
+
options.plural = arg2;
|
|
902
|
+
}
|
|
903
|
+
else if (isArray(arg2)) {
|
|
904
|
+
list = arg2;
|
|
905
|
+
}
|
|
906
|
+
else if (isPlainObject(arg2)) {
|
|
907
|
+
named = arg2;
|
|
908
|
+
}
|
|
909
|
+
if (isString(arg3)) {
|
|
910
|
+
options.locale = arg3;
|
|
911
|
+
}
|
|
912
|
+
else if (isArray(arg3)) {
|
|
913
|
+
list = arg3;
|
|
914
|
+
}
|
|
915
|
+
else if (isPlainObject(arg3)) {
|
|
916
|
+
named = arg3;
|
|
917
|
+
}
|
|
918
|
+
return composer.t(key, list || named || {}, options);
|
|
919
|
+
},
|
|
920
|
+
// te
|
|
921
|
+
te(key, locale) {
|
|
922
|
+
return composer.te(key, locale);
|
|
923
|
+
},
|
|
924
|
+
// tm
|
|
925
|
+
tm(key) {
|
|
926
|
+
return composer.tm(key);
|
|
927
|
+
},
|
|
928
|
+
// getLocaleMessage
|
|
929
|
+
getLocaleMessage(locale) {
|
|
930
|
+
return composer.getLocaleMessage(locale);
|
|
931
|
+
},
|
|
932
|
+
// setLocaleMessage
|
|
933
|
+
setLocaleMessage(locale, message) {
|
|
934
|
+
composer.setLocaleMessage(locale, message);
|
|
935
|
+
},
|
|
936
|
+
// mergeLocaleMessage
|
|
937
|
+
mergeLocaleMessage(locale, message) {
|
|
938
|
+
composer.mergeLocaleMessage(locale, message);
|
|
939
|
+
},
|
|
940
|
+
// d
|
|
941
|
+
d(...args) {
|
|
942
|
+
return composer.d(...args);
|
|
943
|
+
},
|
|
944
|
+
// getDateTimeFormat
|
|
945
|
+
getDateTimeFormat(locale) {
|
|
946
|
+
return composer.getDateTimeFormat(locale);
|
|
947
|
+
},
|
|
948
|
+
// setDateTimeFormat
|
|
949
|
+
setDateTimeFormat(locale, format) {
|
|
950
|
+
composer.setDateTimeFormat(locale, format);
|
|
951
|
+
},
|
|
952
|
+
// mergeDateTimeFormat
|
|
953
|
+
mergeDateTimeFormat(locale, format) {
|
|
954
|
+
composer.mergeDateTimeFormat(locale, format);
|
|
955
|
+
},
|
|
956
|
+
// n
|
|
957
|
+
n(...args) {
|
|
958
|
+
return composer.n(...args);
|
|
959
|
+
},
|
|
960
|
+
// getNumberFormat
|
|
961
|
+
getNumberFormat(locale) {
|
|
962
|
+
return composer.getNumberFormat(locale);
|
|
963
|
+
},
|
|
964
|
+
// setNumberFormat
|
|
965
|
+
setNumberFormat(locale, format) {
|
|
966
|
+
composer.setNumberFormat(locale, format);
|
|
967
|
+
},
|
|
968
|
+
// mergeNumberFormat
|
|
969
|
+
mergeNumberFormat(locale, format) {
|
|
970
|
+
composer.mergeNumberFormat(locale, format);
|
|
971
|
+
},
|
|
972
|
+
// getChoiceIndex
|
|
973
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
974
|
+
getChoiceIndex(choice, choicesLength) {
|
|
975
|
+
(process.env.NODE_ENV !== 'production') &&
|
|
976
|
+
warn(getWarnMessage(10 /* NOT_SUPPORTED_GET_CHOICE_INDEX */));
|
|
977
|
+
return -1;
|
|
978
|
+
},
|
|
979
|
+
// for internal
|
|
980
|
+
__onComponentInstanceCreated(target) {
|
|
981
|
+
const { componentInstanceCreatedListener } = options;
|
|
982
|
+
if (componentInstanceCreatedListener) {
|
|
983
|
+
componentInstanceCreatedListener(target, vueI18n);
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
};
|
|
987
|
+
// for vue-devtools timeline event
|
|
988
|
+
if ((process.env.NODE_ENV !== 'production')) {
|
|
989
|
+
vueI18n.__enableEmitter = (emitter) => {
|
|
990
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
991
|
+
const __composer = composer;
|
|
992
|
+
__composer[EnableEmitter] && __composer[EnableEmitter](emitter);
|
|
993
|
+
};
|
|
994
|
+
vueI18n.__disableEmitter = () => {
|
|
995
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
996
|
+
const __composer = composer;
|
|
997
|
+
__composer[DisableEmitter] && __composer[DisableEmitter]();
|
|
998
|
+
};
|
|
999
|
+
}
|
|
1000
|
+
return vueI18n;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
const baseFormatProps = {
|
|
1004
|
+
tag: {
|
|
1005
|
+
type: [String, Object]
|
|
1006
|
+
},
|
|
1007
|
+
locale: {
|
|
1008
|
+
type: String
|
|
1009
|
+
},
|
|
1010
|
+
scope: {
|
|
1011
|
+
type: String,
|
|
1012
|
+
validator: (val) => val === 'parent' || val === 'global',
|
|
1013
|
+
default: 'parent'
|
|
1014
|
+
},
|
|
1015
|
+
i18n: {
|
|
1016
|
+
type: Object
|
|
1017
|
+
}
|
|
1018
|
+
};
|
|
1019
|
+
|
|
1020
|
+
/**
|
|
1021
|
+
* Translation Component
|
|
1022
|
+
*
|
|
1023
|
+
* @remarks
|
|
1024
|
+
* See the following items for property about details
|
|
1025
|
+
*
|
|
1026
|
+
* @VueI18nSee [TranslationProps](component#translationprops)
|
|
1027
|
+
* @VueI18nSee [BaseFormatProps](component#baseformatprops)
|
|
1028
|
+
* @VueI18nSee [Component Interpolation](../guide/advanced/component)
|
|
1029
|
+
*
|
|
1030
|
+
* @example
|
|
1031
|
+
* ```html
|
|
1032
|
+
* <div id="app">
|
|
1033
|
+
* <!-- ... -->
|
|
1034
|
+
* <i18n path="term" tag="label" for="tos">
|
|
1035
|
+
* <a :href="url" target="_blank">{{ $t('tos') }}</a>
|
|
1036
|
+
* </i18n>
|
|
1037
|
+
* <!-- ... -->
|
|
1038
|
+
* </div>
|
|
1039
|
+
* ```
|
|
1040
|
+
* ```js
|
|
1041
|
+
* import { createApp } from 'vue'
|
|
1042
|
+
* import { createI18n } from 'vue-i18n'
|
|
1043
|
+
*
|
|
1044
|
+
* const messages = {
|
|
1045
|
+
* en: {
|
|
1046
|
+
* tos: 'Term of Service',
|
|
1047
|
+
* term: 'I accept xxx {0}.'
|
|
1048
|
+
* },
|
|
1049
|
+
* ja: {
|
|
1050
|
+
* tos: '利用規約',
|
|
1051
|
+
* term: '私は xxx の{0}に同意します。'
|
|
1052
|
+
* }
|
|
1053
|
+
* }
|
|
1054
|
+
*
|
|
1055
|
+
* const i18n = createI18n({
|
|
1056
|
+
* locale: 'en',
|
|
1057
|
+
* messages
|
|
1058
|
+
* })
|
|
1059
|
+
*
|
|
1060
|
+
* const app = createApp({
|
|
1061
|
+
* data: {
|
|
1062
|
+
* url: '/term'
|
|
1063
|
+
* }
|
|
1064
|
+
* }).use(i18n).mount('#app')
|
|
1065
|
+
* ```
|
|
1066
|
+
*
|
|
1067
|
+
* @VueI18nComponent
|
|
1068
|
+
*/
|
|
1069
|
+
const Translation = {
|
|
1070
|
+
/* eslint-disable */
|
|
1071
|
+
name: 'i18n-t',
|
|
1072
|
+
props: assign({
|
|
1073
|
+
keypath: {
|
|
1074
|
+
type: String,
|
|
1075
|
+
required: true
|
|
1076
|
+
},
|
|
1077
|
+
plural: {
|
|
1078
|
+
type: [Number, String],
|
|
1079
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1080
|
+
validator: (val) => isNumber(val) || !isNaN(val)
|
|
1081
|
+
}
|
|
1082
|
+
}, baseFormatProps),
|
|
1083
|
+
/* eslint-enable */
|
|
1084
|
+
setup(props, context) {
|
|
1085
|
+
const { slots, attrs } = context;
|
|
1086
|
+
const i18n = props.i18n ||
|
|
1087
|
+
useI18n({ useScope: props.scope });
|
|
1088
|
+
const keys = Object.keys(slots).filter(key => key !== '_');
|
|
1089
|
+
return () => {
|
|
1090
|
+
const options = {};
|
|
1091
|
+
if (props.locale) {
|
|
1092
|
+
options.locale = props.locale;
|
|
1093
|
+
}
|
|
1094
|
+
if (props.plural !== undefined) {
|
|
1095
|
+
options.plural = isString(props.plural) ? +props.plural : props.plural;
|
|
1096
|
+
}
|
|
1097
|
+
const arg = getInterpolateArg(context, keys);
|
|
1098
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1099
|
+
const children = i18n[TransrateVNodeSymbol](props.keypath, arg, options);
|
|
1100
|
+
const assignedAttrs = assign({}, attrs);
|
|
1101
|
+
// prettier-ignore
|
|
1102
|
+
return isString(props.tag)
|
|
1103
|
+
? h(props.tag, assignedAttrs, children)
|
|
1104
|
+
: isObject(props.tag)
|
|
1105
|
+
? h(props.tag, assignedAttrs, children)
|
|
1106
|
+
: h(Fragment, assignedAttrs, children);
|
|
1107
|
+
};
|
|
1108
|
+
}
|
|
1109
|
+
};
|
|
1110
|
+
function getInterpolateArg({ slots }, keys) {
|
|
1111
|
+
if (keys.length === 1 && keys[0] === 'default') {
|
|
1112
|
+
// default slot only
|
|
1113
|
+
return slots.default ? slots.default() : [];
|
|
1114
|
+
}
|
|
1115
|
+
else {
|
|
1116
|
+
// named slots
|
|
1117
|
+
return keys.reduce((arg, key) => {
|
|
1118
|
+
const slot = slots[key];
|
|
1119
|
+
if (slot) {
|
|
1120
|
+
arg[key] = slot();
|
|
1121
|
+
}
|
|
1122
|
+
return arg;
|
|
1123
|
+
}, {});
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
function renderFormatter(props, context, slotKeys, partFormatter) {
|
|
1128
|
+
const { slots, attrs } = context;
|
|
1129
|
+
return () => {
|
|
1130
|
+
const options = { part: true };
|
|
1131
|
+
let overrides = {};
|
|
1132
|
+
if (props.locale) {
|
|
1133
|
+
options.locale = props.locale;
|
|
1134
|
+
}
|
|
1135
|
+
if (isString(props.format)) {
|
|
1136
|
+
options.key = props.format;
|
|
1137
|
+
}
|
|
1138
|
+
else if (isObject(props.format)) {
|
|
1139
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1140
|
+
if (isString(props.format.key)) {
|
|
1141
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1142
|
+
options.key = props.format.key;
|
|
1143
|
+
}
|
|
1144
|
+
// Filter out number format options only
|
|
1145
|
+
overrides = Object.keys(props.format).reduce((options, prop) => {
|
|
1146
|
+
return slotKeys.includes(prop)
|
|
1147
|
+
? assign({}, options, { [prop]: props.format[prop] }) // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1148
|
+
: options;
|
|
1149
|
+
}, {});
|
|
1150
|
+
}
|
|
1151
|
+
const parts = partFormatter(...[props.value, options, overrides]);
|
|
1152
|
+
let children = [options.key];
|
|
1153
|
+
if (isArray(parts)) {
|
|
1154
|
+
children = parts.map((part, index) => {
|
|
1155
|
+
const slot = slots[part.type];
|
|
1156
|
+
return slot
|
|
1157
|
+
? slot({ [part.type]: part.value, index, parts })
|
|
1158
|
+
: [part.value];
|
|
1159
|
+
});
|
|
1160
|
+
}
|
|
1161
|
+
else if (isString(parts)) {
|
|
1162
|
+
children = [parts];
|
|
1163
|
+
}
|
|
1164
|
+
const assignedAttrs = assign({}, attrs);
|
|
1165
|
+
// prettier-ignore
|
|
1166
|
+
return isString(props.tag)
|
|
1167
|
+
? h(props.tag, assignedAttrs, children)
|
|
1168
|
+
: isObject(props.tag)
|
|
1169
|
+
? h(props.tag, assignedAttrs, children)
|
|
1170
|
+
: h(Fragment, assignedAttrs, children);
|
|
1171
|
+
};
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
const NUMBER_FORMAT_KEYS = [
|
|
1175
|
+
'localeMatcher',
|
|
1176
|
+
'style',
|
|
1177
|
+
'unit',
|
|
1178
|
+
'unitDisplay',
|
|
1179
|
+
'currency',
|
|
1180
|
+
'currencyDisplay',
|
|
1181
|
+
'useGrouping',
|
|
1182
|
+
'numberingSystem',
|
|
1183
|
+
'minimumIntegerDigits',
|
|
1184
|
+
'minimumFractionDigits',
|
|
1185
|
+
'maximumFractionDigits',
|
|
1186
|
+
'minimumSignificantDigits',
|
|
1187
|
+
'maximumSignificantDigits',
|
|
1188
|
+
'notation',
|
|
1189
|
+
'formatMatcher'
|
|
1190
|
+
];
|
|
1191
|
+
/**
|
|
1192
|
+
* Number Format Component
|
|
1193
|
+
*
|
|
1194
|
+
* @remarks
|
|
1195
|
+
* See the following items for property about details
|
|
1196
|
+
*
|
|
1197
|
+
* @VueI18nSee [FormattableProps](component#formattableprops)
|
|
1198
|
+
* @VueI18nSee [BaseFormatProps](component#baseformatprops)
|
|
1199
|
+
* @VueI18nSee [Custom Formatting](../guide/essentials/number#custom-formatting)
|
|
1200
|
+
*
|
|
1201
|
+
* @VueI18nDanger
|
|
1202
|
+
* Not supported IE, due to no support `Intl.NumberFormat#formatToParts` in [IE](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
|
|
1203
|
+
*
|
|
1204
|
+
* If you want to use it, you need to use [polyfill](https://github.com/formatjs/formatjs/tree/main/packages/intl-numberformat)
|
|
1205
|
+
*
|
|
1206
|
+
* @VueI18nComponent
|
|
1207
|
+
*/
|
|
1208
|
+
const NumberFormat = {
|
|
1209
|
+
/* eslint-disable */
|
|
1210
|
+
name: 'i18n-n',
|
|
1211
|
+
props: assign({
|
|
1212
|
+
value: {
|
|
1213
|
+
type: Number,
|
|
1214
|
+
required: true
|
|
1215
|
+
},
|
|
1216
|
+
format: {
|
|
1217
|
+
type: [String, Object]
|
|
1218
|
+
}
|
|
1219
|
+
}, baseFormatProps),
|
|
1220
|
+
/* eslint-enable */
|
|
1221
|
+
setup(props, context) {
|
|
1222
|
+
const i18n = props.i18n ||
|
|
1223
|
+
useI18n({ useScope: 'parent' });
|
|
1224
|
+
return renderFormatter(props, context, NUMBER_FORMAT_KEYS, (...args) =>
|
|
1225
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1226
|
+
i18n[NumberPartsSymbol](...args));
|
|
1227
|
+
}
|
|
1228
|
+
};
|
|
1229
|
+
|
|
1230
|
+
const DATETIME_FORMAT_KEYS = [
|
|
1231
|
+
'dateStyle',
|
|
1232
|
+
'timeStyle',
|
|
1233
|
+
'fractionalSecondDigits',
|
|
1234
|
+
'calendar',
|
|
1235
|
+
'dayPeriod',
|
|
1236
|
+
'numberingSystem',
|
|
1237
|
+
'localeMatcher',
|
|
1238
|
+
'timeZone',
|
|
1239
|
+
'hour12',
|
|
1240
|
+
'hourCycle',
|
|
1241
|
+
'formatMatcher',
|
|
1242
|
+
'weekday',
|
|
1243
|
+
'era',
|
|
1244
|
+
'year',
|
|
1245
|
+
'month',
|
|
1246
|
+
'day',
|
|
1247
|
+
'hour',
|
|
1248
|
+
'minute',
|
|
1249
|
+
'second',
|
|
1250
|
+
'timeZoneName'
|
|
1251
|
+
];
|
|
1252
|
+
/**
|
|
1253
|
+
* Datetime Format Component
|
|
1254
|
+
*
|
|
1255
|
+
* @remarks
|
|
1256
|
+
* See the following items for property about details
|
|
1257
|
+
*
|
|
1258
|
+
* @VueI18nSee [FormattableProps](component#formattableprops)
|
|
1259
|
+
* @VueI18nSee [BaseFormatProps](component#baseformatprops)
|
|
1260
|
+
* @VueI18nSee [Custom Formatting](../guide/essentials/datetime#custom-formatting)
|
|
1261
|
+
*
|
|
1262
|
+
* @VueI18nDanger
|
|
1263
|
+
* Not supported IE, due to no support `Intl.DateTimeFormat#formatToParts` in [IE](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts)
|
|
1264
|
+
*
|
|
1265
|
+
* If you want to use it, you need to use [polyfill](https://github.com/formatjs/formatjs/tree/main/packages/intl-datetimeformat)
|
|
1266
|
+
*
|
|
1267
|
+
* @VueI18nComponent
|
|
1268
|
+
*/
|
|
1269
|
+
const DatetimeFormat = {
|
|
1270
|
+
/* eslint-disable */
|
|
1271
|
+
name: 'i18n-d',
|
|
1272
|
+
props: assign({
|
|
1273
|
+
value: {
|
|
1274
|
+
type: [Number, Date],
|
|
1275
|
+
required: true
|
|
1276
|
+
},
|
|
1277
|
+
format: {
|
|
1278
|
+
type: [String, Object]
|
|
1279
|
+
}
|
|
1280
|
+
}, baseFormatProps),
|
|
1281
|
+
/* eslint-enable */
|
|
1282
|
+
setup(props, context) {
|
|
1283
|
+
const i18n = props.i18n ||
|
|
1284
|
+
useI18n({ useScope: 'parent' });
|
|
1285
|
+
return renderFormatter(props, context, DATETIME_FORMAT_KEYS, (...args) =>
|
|
1286
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1287
|
+
i18n[DatetimePartsSymbol](...args));
|
|
1288
|
+
}
|
|
1289
|
+
};
|
|
1290
|
+
|
|
1291
|
+
function getComposer$2(i18n, instance) {
|
|
1292
|
+
const i18nInternal = i18n;
|
|
1293
|
+
if (i18n.mode === 'composition') {
|
|
1294
|
+
return (i18nInternal.__getInstance(instance) || i18n.global);
|
|
1295
|
+
}
|
|
1296
|
+
else {
|
|
1297
|
+
const vueI18n = i18nInternal.__getInstance(instance);
|
|
1298
|
+
return vueI18n != null
|
|
1299
|
+
? vueI18n.__composer
|
|
1300
|
+
: i18n.global.__composer;
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
function vTDirective(i18n) {
|
|
1304
|
+
const bind = (el, { instance, value, modifiers }) => {
|
|
1305
|
+
/* istanbul ignore if */
|
|
1306
|
+
if (!instance || !instance.$) {
|
|
1307
|
+
throw createI18nError(22 /* UNEXPECTED_ERROR */);
|
|
1308
|
+
}
|
|
1309
|
+
const composer = getComposer$2(i18n, instance.$);
|
|
1310
|
+
if ((process.env.NODE_ENV !== 'production') && modifiers.preserve) {
|
|
1311
|
+
warn(getWarnMessage(7 /* NOT_SUPPORTED_PRESERVE */));
|
|
1312
|
+
}
|
|
1313
|
+
const parsedValue = parseValue(value);
|
|
1314
|
+
el.textContent = composer.t(...makeParams(parsedValue));
|
|
1315
|
+
};
|
|
1316
|
+
return {
|
|
1317
|
+
beforeMount: bind,
|
|
1318
|
+
beforeUpdate: bind
|
|
1319
|
+
};
|
|
1320
|
+
}
|
|
1321
|
+
function parseValue(value) {
|
|
1322
|
+
if (isString(value)) {
|
|
1323
|
+
return { path: value };
|
|
1324
|
+
}
|
|
1325
|
+
else if (isPlainObject(value)) {
|
|
1326
|
+
if (!('path' in value)) {
|
|
1327
|
+
throw createI18nError(19 /* REQUIRED_VALUE */, 'path');
|
|
1328
|
+
}
|
|
1329
|
+
return value;
|
|
1330
|
+
}
|
|
1331
|
+
else {
|
|
1332
|
+
throw createI18nError(20 /* INVALID_VALUE */);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
function makeParams(value) {
|
|
1336
|
+
const { path, locale, args, choice, plural } = value;
|
|
1337
|
+
const options = {};
|
|
1338
|
+
const named = args || {};
|
|
1339
|
+
if (isString(locale)) {
|
|
1340
|
+
options.locale = locale;
|
|
1341
|
+
}
|
|
1342
|
+
if (isNumber(choice)) {
|
|
1343
|
+
options.plural = choice;
|
|
1344
|
+
}
|
|
1345
|
+
if (isNumber(plural)) {
|
|
1346
|
+
options.plural = plural;
|
|
1347
|
+
}
|
|
1348
|
+
return [path, named, options];
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
function apply(app, i18n, ...options) {
|
|
1352
|
+
const pluginOptions = isPlainObject(options[0])
|
|
1353
|
+
? options[0]
|
|
1354
|
+
: {};
|
|
1355
|
+
const useI18nComponentName = !!pluginOptions.useI18nComponentName;
|
|
1356
|
+
const globalInstall = isBoolean(pluginOptions.globalInstall)
|
|
1357
|
+
? pluginOptions.globalInstall
|
|
1358
|
+
: true;
|
|
1359
|
+
if ((process.env.NODE_ENV !== 'production') && globalInstall && useI18nComponentName) {
|
|
1360
|
+
warn(getWarnMessage(11 /* COMPONENT_NAME_LEGACY_COMPATIBLE */, {
|
|
1361
|
+
name: Translation.name
|
|
1362
|
+
}));
|
|
1363
|
+
}
|
|
1364
|
+
if (globalInstall) {
|
|
1365
|
+
// install components
|
|
1366
|
+
app.component(!useI18nComponentName ? Translation.name : 'i18n', Translation);
|
|
1367
|
+
app.component(NumberFormat.name, NumberFormat);
|
|
1368
|
+
app.component(DatetimeFormat.name, DatetimeFormat);
|
|
1369
|
+
}
|
|
1370
|
+
// install directive
|
|
1371
|
+
app.directive('t', vTDirective(i18n));
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
const VUE_I18N_COMPONENT_TYPES = 'vue-i18n: composer properties';
|
|
1375
|
+
let devtoolsApi;
|
|
1376
|
+
async function enableDevTools(app, i18n) {
|
|
1377
|
+
return new Promise((resolve, reject) => {
|
|
1378
|
+
try {
|
|
1379
|
+
setupDevtoolsPlugin({
|
|
1380
|
+
id: "vue-devtools-plugin-vue-i18n" /* PLUGIN */,
|
|
1381
|
+
label: VueDevToolsLabels["vue-devtools-plugin-vue-i18n" /* PLUGIN */],
|
|
1382
|
+
packageName: 'vue-i18n',
|
|
1383
|
+
homepage: 'https://vue-i18n.intlify.dev',
|
|
1384
|
+
logo: 'https://vue-i18n.intlify.dev/vue-i18n-devtools-logo.png',
|
|
1385
|
+
componentStateTypes: [VUE_I18N_COMPONENT_TYPES],
|
|
1386
|
+
app
|
|
1387
|
+
}, api => {
|
|
1388
|
+
devtoolsApi = api;
|
|
1389
|
+
api.on.visitComponentTree(({ componentInstance, treeNode }) => {
|
|
1390
|
+
updateComponentTreeTags(componentInstance, treeNode, i18n);
|
|
1391
|
+
});
|
|
1392
|
+
api.on.inspectComponent(({ componentInstance, instanceData }) => {
|
|
1393
|
+
if (componentInstance.vnode.el.__VUE_I18N__ && instanceData) {
|
|
1394
|
+
if (i18n.mode === 'legacy') {
|
|
1395
|
+
// ignore global scope on legacy mode
|
|
1396
|
+
if (componentInstance.vnode.el.__VUE_I18N__ !==
|
|
1397
|
+
i18n.global.__composer) {
|
|
1398
|
+
inspectComposer(instanceData, componentInstance.vnode.el.__VUE_I18N__);
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
else {
|
|
1402
|
+
inspectComposer(instanceData, componentInstance.vnode.el.__VUE_I18N__);
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
});
|
|
1406
|
+
api.addInspector({
|
|
1407
|
+
id: "vue-i18n-resource-inspector" /* CUSTOM_INSPECTOR */,
|
|
1408
|
+
label: VueDevToolsLabels["vue-i18n-resource-inspector" /* CUSTOM_INSPECTOR */],
|
|
1409
|
+
icon: 'language',
|
|
1410
|
+
treeFilterPlaceholder: VueDevToolsPlaceholders["vue-i18n-resource-inspector" /* CUSTOM_INSPECTOR */]
|
|
1411
|
+
});
|
|
1412
|
+
api.on.getInspectorTree(payload => {
|
|
1413
|
+
if (payload.app === app &&
|
|
1414
|
+
payload.inspectorId === "vue-i18n-resource-inspector" /* CUSTOM_INSPECTOR */) {
|
|
1415
|
+
registerScope(payload, i18n);
|
|
1416
|
+
}
|
|
1417
|
+
});
|
|
1418
|
+
api.on.getInspectorState(payload => {
|
|
1419
|
+
if (payload.app === app &&
|
|
1420
|
+
payload.inspectorId === "vue-i18n-resource-inspector" /* CUSTOM_INSPECTOR */) {
|
|
1421
|
+
inspectScope(payload, i18n);
|
|
1422
|
+
}
|
|
1423
|
+
});
|
|
1424
|
+
api.on.editInspectorState(payload => {
|
|
1425
|
+
if (payload.app === app &&
|
|
1426
|
+
payload.inspectorId === "vue-i18n-resource-inspector" /* CUSTOM_INSPECTOR */) {
|
|
1427
|
+
editScope(payload, i18n);
|
|
1428
|
+
}
|
|
1429
|
+
});
|
|
1430
|
+
api.addTimelineLayer({
|
|
1431
|
+
id: "vue-i18n-timeline" /* TIMELINE */,
|
|
1432
|
+
label: VueDevToolsLabels["vue-i18n-timeline" /* TIMELINE */],
|
|
1433
|
+
color: VueDevToolsTimelineColors["vue-i18n-timeline" /* TIMELINE */]
|
|
1434
|
+
});
|
|
1435
|
+
resolve(true);
|
|
1436
|
+
});
|
|
1437
|
+
}
|
|
1438
|
+
catch (e) {
|
|
1439
|
+
console.error(e);
|
|
1440
|
+
reject(false);
|
|
1441
|
+
}
|
|
1442
|
+
});
|
|
1443
|
+
}
|
|
1444
|
+
function updateComponentTreeTags(instance, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1445
|
+
treeNode, i18n) {
|
|
1446
|
+
// prettier-ignore
|
|
1447
|
+
const global = i18n.mode === 'composition'
|
|
1448
|
+
? i18n.global
|
|
1449
|
+
: i18n.global.__composer;
|
|
1450
|
+
if (instance && instance.vnode.el.__VUE_I18N__) {
|
|
1451
|
+
// add custom tags local scope only
|
|
1452
|
+
if (instance.vnode.el.__VUE_I18N__ !== global) {
|
|
1453
|
+
const label = instance.type.name || instance.type.displayName || instance.type.__file;
|
|
1454
|
+
const tag = {
|
|
1455
|
+
label: `i18n (${label} Scope)`,
|
|
1456
|
+
textColor: 0x000000,
|
|
1457
|
+
backgroundColor: 0xffcd19
|
|
1458
|
+
};
|
|
1459
|
+
treeNode.tags.push(tag);
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
function inspectComposer(instanceData, composer) {
|
|
1464
|
+
const type = VUE_I18N_COMPONENT_TYPES;
|
|
1465
|
+
instanceData.state.push({
|
|
1466
|
+
type,
|
|
1467
|
+
key: 'locale',
|
|
1468
|
+
editable: true,
|
|
1469
|
+
value: composer.locale.value
|
|
1470
|
+
});
|
|
1471
|
+
instanceData.state.push({
|
|
1472
|
+
type,
|
|
1473
|
+
key: 'availableLocales',
|
|
1474
|
+
editable: false,
|
|
1475
|
+
value: composer.availableLocales
|
|
1476
|
+
});
|
|
1477
|
+
instanceData.state.push({
|
|
1478
|
+
type,
|
|
1479
|
+
key: 'fallbackLocale',
|
|
1480
|
+
editable: true,
|
|
1481
|
+
value: composer.fallbackLocale.value
|
|
1482
|
+
});
|
|
1483
|
+
instanceData.state.push({
|
|
1484
|
+
type,
|
|
1485
|
+
key: 'inheritLocale',
|
|
1486
|
+
editable: true,
|
|
1487
|
+
value: composer.inheritLocale
|
|
1488
|
+
});
|
|
1489
|
+
instanceData.state.push({
|
|
1490
|
+
type,
|
|
1491
|
+
key: 'messages',
|
|
1492
|
+
editable: false,
|
|
1493
|
+
value: getLocaleMessageValue(composer.messages.value)
|
|
1494
|
+
});
|
|
1495
|
+
instanceData.state.push({
|
|
1496
|
+
type,
|
|
1497
|
+
key: 'datetimeFormats',
|
|
1498
|
+
editable: false,
|
|
1499
|
+
value: composer.datetimeFormats.value
|
|
1500
|
+
});
|
|
1501
|
+
instanceData.state.push({
|
|
1502
|
+
type,
|
|
1503
|
+
key: 'numberFormats',
|
|
1504
|
+
editable: false,
|
|
1505
|
+
value: composer.numberFormats.value
|
|
1506
|
+
});
|
|
1507
|
+
}
|
|
1508
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1509
|
+
function getLocaleMessageValue(messages) {
|
|
1510
|
+
const value = {};
|
|
1511
|
+
Object.keys(messages).forEach((key) => {
|
|
1512
|
+
const v = messages[key];
|
|
1513
|
+
if (isFunction(v) && 'source' in v) {
|
|
1514
|
+
value[key] = getMessageFunctionDetails(v);
|
|
1515
|
+
}
|
|
1516
|
+
else if (isObject(v)) {
|
|
1517
|
+
value[key] = getLocaleMessageValue(v);
|
|
1518
|
+
}
|
|
1519
|
+
else {
|
|
1520
|
+
value[key] = v;
|
|
1521
|
+
}
|
|
1522
|
+
});
|
|
1523
|
+
return value;
|
|
1524
|
+
}
|
|
1525
|
+
const ESC = {
|
|
1526
|
+
'<': '<',
|
|
1527
|
+
'>': '>',
|
|
1528
|
+
'"': '"',
|
|
1529
|
+
'&': '&'
|
|
1530
|
+
};
|
|
1531
|
+
function escape(s) {
|
|
1532
|
+
return s.replace(/[<>"&]/g, escapeChar);
|
|
1533
|
+
}
|
|
1534
|
+
function escapeChar(a) {
|
|
1535
|
+
return ESC[a] || a;
|
|
1536
|
+
}
|
|
1537
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1538
|
+
function getMessageFunctionDetails(func) {
|
|
1539
|
+
const argString = func.source ? `("${escape(func.source)}")` : `(?)`;
|
|
1540
|
+
return {
|
|
1541
|
+
_custom: {
|
|
1542
|
+
type: 'function',
|
|
1543
|
+
display: `<span>ƒ</span> ${argString}`
|
|
1544
|
+
}
|
|
1545
|
+
};
|
|
1546
|
+
}
|
|
1547
|
+
function registerScope(payload, i18n) {
|
|
1548
|
+
payload.rootNodes.push({
|
|
1549
|
+
id: 'global',
|
|
1550
|
+
label: 'Global Scope'
|
|
1551
|
+
});
|
|
1552
|
+
// prettier-ignore
|
|
1553
|
+
const global = i18n.mode === 'composition'
|
|
1554
|
+
? i18n.global
|
|
1555
|
+
: i18n.global.__composer;
|
|
1556
|
+
for (const [keyInstance, instance] of i18n.__instances) {
|
|
1557
|
+
// prettier-ignore
|
|
1558
|
+
const composer = i18n.mode === 'composition'
|
|
1559
|
+
? instance
|
|
1560
|
+
: instance.__composer;
|
|
1561
|
+
if (global === composer) {
|
|
1562
|
+
continue;
|
|
1563
|
+
}
|
|
1564
|
+
const label = keyInstance.type.name ||
|
|
1565
|
+
keyInstance.type.displayName ||
|
|
1566
|
+
keyInstance.type.__file;
|
|
1567
|
+
payload.rootNodes.push({
|
|
1568
|
+
id: composer.id.toString(),
|
|
1569
|
+
label: `${label} Scope`
|
|
1570
|
+
});
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
function getComposer$1(nodeId, i18n) {
|
|
1574
|
+
if (nodeId === 'global') {
|
|
1575
|
+
return i18n.mode === 'composition'
|
|
1576
|
+
? i18n.global
|
|
1577
|
+
: i18n.global.__composer;
|
|
1578
|
+
}
|
|
1579
|
+
else {
|
|
1580
|
+
const instance = Array.from(i18n.__instances.values()).find(item => item.id.toString() === nodeId);
|
|
1581
|
+
if (instance) {
|
|
1582
|
+
return i18n.mode === 'composition'
|
|
1583
|
+
? instance
|
|
1584
|
+
: instance.__composer;
|
|
1585
|
+
}
|
|
1586
|
+
else {
|
|
1587
|
+
return null;
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
function inspectScope(payload, i18n) {
|
|
1592
|
+
const composer = getComposer$1(payload.nodeId, i18n);
|
|
1593
|
+
if (composer) {
|
|
1594
|
+
payload.state = makeScopeInspectState(composer);
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
function makeScopeInspectState(composer) {
|
|
1598
|
+
const state = {};
|
|
1599
|
+
const localeType = 'Locale related info';
|
|
1600
|
+
const localeStates = [
|
|
1601
|
+
{
|
|
1602
|
+
type: localeType,
|
|
1603
|
+
key: 'locale',
|
|
1604
|
+
editable: true,
|
|
1605
|
+
value: composer.locale.value
|
|
1606
|
+
},
|
|
1607
|
+
{
|
|
1608
|
+
type: localeType,
|
|
1609
|
+
key: 'fallbackLocale',
|
|
1610
|
+
editable: true,
|
|
1611
|
+
value: composer.fallbackLocale.value
|
|
1612
|
+
},
|
|
1613
|
+
{
|
|
1614
|
+
type: localeType,
|
|
1615
|
+
key: 'availableLocales',
|
|
1616
|
+
editable: false,
|
|
1617
|
+
value: composer.availableLocales
|
|
1618
|
+
},
|
|
1619
|
+
{
|
|
1620
|
+
type: localeType,
|
|
1621
|
+
key: 'inheritLocale',
|
|
1622
|
+
editable: true,
|
|
1623
|
+
value: composer.inheritLocale
|
|
1624
|
+
}
|
|
1625
|
+
];
|
|
1626
|
+
state[localeType] = localeStates;
|
|
1627
|
+
const localeMessagesType = 'Locale messages info';
|
|
1628
|
+
const localeMessagesStates = [
|
|
1629
|
+
{
|
|
1630
|
+
type: localeMessagesType,
|
|
1631
|
+
key: 'messages',
|
|
1632
|
+
editable: false,
|
|
1633
|
+
value: getLocaleMessageValue(composer.messages.value)
|
|
1634
|
+
}
|
|
1635
|
+
];
|
|
1636
|
+
state[localeMessagesType] = localeMessagesStates;
|
|
1637
|
+
const datetimeFormatsType = 'Datetime formats info';
|
|
1638
|
+
const datetimeFormatsStates = [
|
|
1639
|
+
{
|
|
1640
|
+
type: datetimeFormatsType,
|
|
1641
|
+
key: 'datetimeFormats',
|
|
1642
|
+
editable: false,
|
|
1643
|
+
value: composer.datetimeFormats.value
|
|
1644
|
+
}
|
|
1645
|
+
];
|
|
1646
|
+
state[datetimeFormatsType] = datetimeFormatsStates;
|
|
1647
|
+
const numberFormatsType = 'Datetime formats info';
|
|
1648
|
+
const numberFormatsStates = [
|
|
1649
|
+
{
|
|
1650
|
+
type: numberFormatsType,
|
|
1651
|
+
key: 'numberFormats',
|
|
1652
|
+
editable: false,
|
|
1653
|
+
value: composer.numberFormats.value
|
|
1654
|
+
}
|
|
1655
|
+
];
|
|
1656
|
+
state[numberFormatsType] = numberFormatsStates;
|
|
1657
|
+
return state;
|
|
1658
|
+
}
|
|
1659
|
+
function addTimelineEvent(event, payload) {
|
|
1660
|
+
if (devtoolsApi) {
|
|
1661
|
+
let groupId;
|
|
1662
|
+
if (payload && 'groupId' in payload) {
|
|
1663
|
+
groupId = payload.groupId;
|
|
1664
|
+
delete payload.groupId;
|
|
1665
|
+
}
|
|
1666
|
+
devtoolsApi.addTimelineEvent({
|
|
1667
|
+
layerId: "vue-i18n-timeline" /* TIMELINE */,
|
|
1668
|
+
event: {
|
|
1669
|
+
title: event,
|
|
1670
|
+
groupId,
|
|
1671
|
+
time: Date.now(),
|
|
1672
|
+
meta: {},
|
|
1673
|
+
data: payload || {},
|
|
1674
|
+
logType: event === "compile-error" /* COMPILE_ERROR */
|
|
1675
|
+
? 'error'
|
|
1676
|
+
: event === "fallback" /* FALBACK */ ||
|
|
1677
|
+
event === "missing" /* MISSING */
|
|
1678
|
+
? 'warning'
|
|
1679
|
+
: 'default'
|
|
1680
|
+
}
|
|
1681
|
+
});
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
function editScope(payload, i18n) {
|
|
1685
|
+
const composer = getComposer$1(payload.nodeId, i18n);
|
|
1686
|
+
if (composer) {
|
|
1687
|
+
const [field] = payload.path;
|
|
1688
|
+
if (field === 'locale' && isString(payload.state.value)) {
|
|
1689
|
+
composer.locale.value = payload.state.value;
|
|
1690
|
+
}
|
|
1691
|
+
else if (field === 'fallbackLocale' &&
|
|
1692
|
+
(isString(payload.state.value) ||
|
|
1693
|
+
isArray(payload.state.value) ||
|
|
1694
|
+
isObject(payload.state.value))) {
|
|
1695
|
+
composer.fallbackLocale.value = payload.state.value;
|
|
1696
|
+
}
|
|
1697
|
+
else if (field === 'inheritLocale' && isBoolean(payload.state.value)) {
|
|
1698
|
+
composer.inheritLocale = payload.state.value;
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
// supports compatibility for legacy vue-i18n APIs
|
|
1704
|
+
function defineMixin(vuei18n, composer, i18n) {
|
|
1705
|
+
return {
|
|
1706
|
+
beforeCreate() {
|
|
1707
|
+
const instance = getCurrentInstance();
|
|
1708
|
+
/* istanbul ignore if */
|
|
1709
|
+
if (!instance) {
|
|
1710
|
+
throw createI18nError(22 /* UNEXPECTED_ERROR */);
|
|
1711
|
+
}
|
|
1712
|
+
const options = this.$options;
|
|
1713
|
+
if (options.i18n) {
|
|
1714
|
+
const optionsI18n = options.i18n;
|
|
1715
|
+
if (options.__i18n) {
|
|
1716
|
+
optionsI18n.__i18n = options.__i18n;
|
|
1717
|
+
}
|
|
1718
|
+
optionsI18n.__root = composer;
|
|
1719
|
+
if (this === this.$root) {
|
|
1720
|
+
this.$i18n = mergeToRoot(vuei18n, optionsI18n);
|
|
1721
|
+
}
|
|
1722
|
+
else {
|
|
1723
|
+
this.$i18n = createVueI18n(optionsI18n);
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
else if (options.__i18n) {
|
|
1727
|
+
if (this === this.$root) {
|
|
1728
|
+
this.$i18n = mergeToRoot(vuei18n, options);
|
|
1729
|
+
}
|
|
1730
|
+
else {
|
|
1731
|
+
this.$i18n = createVueI18n({
|
|
1732
|
+
__i18n: options.__i18n,
|
|
1733
|
+
__root: composer
|
|
1734
|
+
});
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
else {
|
|
1738
|
+
// set global
|
|
1739
|
+
this.$i18n = vuei18n;
|
|
1740
|
+
}
|
|
1741
|
+
vuei18n.__onComponentInstanceCreated(this.$i18n);
|
|
1742
|
+
i18n.__setInstance(instance, this.$i18n);
|
|
1743
|
+
// defines vue-i18n legacy APIs
|
|
1744
|
+
this.$t = (...args) => this.$i18n.t(...args);
|
|
1745
|
+
this.$rt = (...args) => this.$i18n.rt(...args);
|
|
1746
|
+
this.$tc = (...args) => this.$i18n.tc(...args);
|
|
1747
|
+
this.$te = (key, locale) => this.$i18n.te(key, locale);
|
|
1748
|
+
this.$d = (...args) => this.$i18n.d(...args);
|
|
1749
|
+
this.$n = (...args) => this.$i18n.n(...args);
|
|
1750
|
+
this.$tm = (key) => this.$i18n.tm(key);
|
|
1751
|
+
},
|
|
1752
|
+
mounted() {
|
|
1753
|
+
/* istanbul ignore if */
|
|
1754
|
+
if (((process.env.NODE_ENV !== 'production') || __VUE_I18N_PROD_DEVTOOLS__) && !false) {
|
|
1755
|
+
this.$el.__VUE_I18N__ = this.$i18n.__composer;
|
|
1756
|
+
const emitter = (this.__v_emitter = createEmitter());
|
|
1757
|
+
const _vueI18n = this.$i18n;
|
|
1758
|
+
_vueI18n.__enableEmitter && _vueI18n.__enableEmitter(emitter);
|
|
1759
|
+
emitter.on('*', addTimelineEvent);
|
|
1760
|
+
}
|
|
1761
|
+
},
|
|
1762
|
+
beforeUnmount() {
|
|
1763
|
+
const instance = getCurrentInstance();
|
|
1764
|
+
/* istanbul ignore if */
|
|
1765
|
+
if (!instance) {
|
|
1766
|
+
throw createI18nError(22 /* UNEXPECTED_ERROR */);
|
|
1767
|
+
}
|
|
1768
|
+
/* istanbul ignore if */
|
|
1769
|
+
if (((process.env.NODE_ENV !== 'production') || __VUE_I18N_PROD_DEVTOOLS__) && !false) {
|
|
1770
|
+
if (this.__v_emitter) {
|
|
1771
|
+
this.__v_emitter.off('*', addTimelineEvent);
|
|
1772
|
+
delete this.__v_emitter;
|
|
1773
|
+
}
|
|
1774
|
+
const _vueI18n = this.$i18n;
|
|
1775
|
+
_vueI18n.__disableEmitter && _vueI18n.__disableEmitter();
|
|
1776
|
+
delete this.$el.__VUE_I18N__;
|
|
1777
|
+
}
|
|
1778
|
+
delete this.$t;
|
|
1779
|
+
delete this.$rt;
|
|
1780
|
+
delete this.$tc;
|
|
1781
|
+
delete this.$te;
|
|
1782
|
+
delete this.$d;
|
|
1783
|
+
delete this.$n;
|
|
1784
|
+
delete this.$tm;
|
|
1785
|
+
i18n.__deleteInstance(instance);
|
|
1786
|
+
delete this.$i18n;
|
|
1787
|
+
}
|
|
1788
|
+
};
|
|
1789
|
+
}
|
|
1790
|
+
function mergeToRoot(root, options) {
|
|
1791
|
+
root.locale = options.locale || root.locale;
|
|
1792
|
+
root.fallbackLocale = options.fallbackLocale || root.fallbackLocale;
|
|
1793
|
+
root.missing = options.missing || root.missing;
|
|
1794
|
+
root.silentTranslationWarn =
|
|
1795
|
+
options.silentTranslationWarn || root.silentFallbackWarn;
|
|
1796
|
+
root.silentFallbackWarn =
|
|
1797
|
+
options.silentFallbackWarn || root.silentFallbackWarn;
|
|
1798
|
+
root.formatFallbackMessages =
|
|
1799
|
+
options.formatFallbackMessages || root.formatFallbackMessages;
|
|
1800
|
+
root.postTranslation = options.postTranslation || root.postTranslation;
|
|
1801
|
+
root.warnHtmlInMessage = options.warnHtmlInMessage || root.warnHtmlInMessage;
|
|
1802
|
+
root.escapeParameterHtml =
|
|
1803
|
+
options.escapeParameterHtml || root.escapeParameterHtml;
|
|
1804
|
+
root.sync = options.sync || root.sync;
|
|
1805
|
+
root.__composer[SetPluralRulesSymbol](options.pluralizationRules || root.pluralizationRules);
|
|
1806
|
+
const messages = getLocaleMessages(root.locale, {
|
|
1807
|
+
messages: options.messages,
|
|
1808
|
+
__i18n: options.__i18n
|
|
1809
|
+
});
|
|
1810
|
+
Object.keys(messages).forEach(locale => root.mergeLocaleMessage(locale, messages[locale]));
|
|
1811
|
+
if (options.datetimeFormats) {
|
|
1812
|
+
Object.keys(options.datetimeFormats).forEach(locale => root.mergeDateTimeFormat(locale, options.datetimeFormats[locale]));
|
|
1813
|
+
}
|
|
1814
|
+
if (options.numberFormats) {
|
|
1815
|
+
Object.keys(options.numberFormats).forEach(locale => root.mergeNumberFormat(locale, options.numberFormats[locale]));
|
|
1816
|
+
}
|
|
1817
|
+
return root;
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1820
|
+
/**
|
|
1821
|
+
* Vue I18n factory
|
|
1822
|
+
*
|
|
1823
|
+
* @param options - An options, see the {@link I18nOptions}
|
|
1824
|
+
*
|
|
1825
|
+
* @returns {@link I18n} instance
|
|
1826
|
+
*
|
|
1827
|
+
* @remarks
|
|
1828
|
+
* If you use Legacy API mode, you need toto specify {@link VueI18nOptions} and `legacy: true` option.
|
|
1829
|
+
*
|
|
1830
|
+
* If you use composition API mode, you need to specify {@link ComposerOptions}.
|
|
1831
|
+
*
|
|
1832
|
+
* @VueI18nSee [Getting Started](../guide/)
|
|
1833
|
+
* @VueI18nSee [Composition API](../guide/advanced/composition)
|
|
1834
|
+
*
|
|
1835
|
+
* @example
|
|
1836
|
+
* case: for Legacy API
|
|
1837
|
+
* ```js
|
|
1838
|
+
* import { createApp } from 'vue'
|
|
1839
|
+
* import { createI18n } from 'vue-i18n'
|
|
1840
|
+
*
|
|
1841
|
+
* // call with I18n option
|
|
1842
|
+
* const i18n = createI18n({
|
|
1843
|
+
* locale: 'ja',
|
|
1844
|
+
* messages: {
|
|
1845
|
+
* en: { ... },
|
|
1846
|
+
* ja: { ... }
|
|
1847
|
+
* }
|
|
1848
|
+
* })
|
|
1849
|
+
*
|
|
1850
|
+
* const App = {
|
|
1851
|
+
* // ...
|
|
1852
|
+
* }
|
|
1853
|
+
*
|
|
1854
|
+
* const app = createApp(App)
|
|
1855
|
+
*
|
|
1856
|
+
* // install!
|
|
1857
|
+
* app.use(i18n)
|
|
1858
|
+
* app.mount('#app')
|
|
1859
|
+
* ```
|
|
1860
|
+
*
|
|
1861
|
+
* @example
|
|
1862
|
+
* case: for composition API
|
|
1863
|
+
* ```js
|
|
1864
|
+
* import { createApp } from 'vue'
|
|
1865
|
+
* import { createI18n, useI18n } from 'vue-i18n'
|
|
1866
|
+
*
|
|
1867
|
+
* // call with I18n option
|
|
1868
|
+
* const i18n = createI18n({
|
|
1869
|
+
* legacy: false, // you must specify 'legacy: false' option
|
|
1870
|
+
* locale: 'ja',
|
|
1871
|
+
* messages: {
|
|
1872
|
+
* en: { ... },
|
|
1873
|
+
* ja: { ... }
|
|
1874
|
+
* }
|
|
1875
|
+
* })
|
|
1876
|
+
*
|
|
1877
|
+
* const App = {
|
|
1878
|
+
* setup() {
|
|
1879
|
+
* // ...
|
|
1880
|
+
* const { t } = useI18n({ ... })
|
|
1881
|
+
* return { ... , t }
|
|
1882
|
+
* }
|
|
1883
|
+
* }
|
|
1884
|
+
*
|
|
1885
|
+
* const app = createApp(App)
|
|
1886
|
+
*
|
|
1887
|
+
* // install!
|
|
1888
|
+
* app.use(i18n)
|
|
1889
|
+
* app.mount('#app')
|
|
1890
|
+
* ```
|
|
1891
|
+
*
|
|
1892
|
+
* @VueI18nGeneral
|
|
1893
|
+
*/
|
|
1894
|
+
function createI18n(options = {}) {
|
|
1895
|
+
// prettier-ignore
|
|
1896
|
+
const __legacyMode = __VUE_I18N_LEGACY_API__ && isBoolean(options.legacy)
|
|
1897
|
+
? options.legacy
|
|
1898
|
+
: __VUE_I18N_LEGACY_API__;
|
|
1899
|
+
const __globalInjection = !!options.globalInjection;
|
|
1900
|
+
const __instances = new Map();
|
|
1901
|
+
// prettier-ignore
|
|
1902
|
+
const __global = __VUE_I18N_LEGACY_API__ && __legacyMode
|
|
1903
|
+
? createVueI18n(options)
|
|
1904
|
+
: createComposer(options);
|
|
1905
|
+
const symbol = makeSymbol((process.env.NODE_ENV !== 'production') ? 'vue-i18n' : '');
|
|
1906
|
+
const i18n = {
|
|
1907
|
+
// mode
|
|
1908
|
+
get mode() {
|
|
1909
|
+
// prettier-ignore
|
|
1910
|
+
return __VUE_I18N_LEGACY_API__
|
|
1911
|
+
? __legacyMode
|
|
1912
|
+
? 'legacy'
|
|
1913
|
+
: 'composition'
|
|
1914
|
+
: 'composition';
|
|
1915
|
+
},
|
|
1916
|
+
// install plugin
|
|
1917
|
+
async install(app, ...options) {
|
|
1918
|
+
if (((process.env.NODE_ENV !== 'production') || __VUE_I18N_PROD_DEVTOOLS__) && !false) {
|
|
1919
|
+
app.__VUE_I18N__ = i18n;
|
|
1920
|
+
}
|
|
1921
|
+
// setup global provider
|
|
1922
|
+
app.__VUE_I18N_SYMBOL__ = symbol;
|
|
1923
|
+
app.provide(app.__VUE_I18N_SYMBOL__, i18n);
|
|
1924
|
+
// global method and properties injection for Composition API
|
|
1925
|
+
if (!__legacyMode && __globalInjection) {
|
|
1926
|
+
injectGlobalFields(app, i18n.global);
|
|
1927
|
+
}
|
|
1928
|
+
// install built-in components and directive
|
|
1929
|
+
if (__VUE_I18N_FULL_INSTALL__) {
|
|
1930
|
+
apply(app, i18n, ...options);
|
|
1931
|
+
}
|
|
1932
|
+
// setup mixin for Legacy API
|
|
1933
|
+
if (__VUE_I18N_LEGACY_API__ && __legacyMode) {
|
|
1934
|
+
app.mixin(defineMixin(__global, __global.__composer, i18n));
|
|
1935
|
+
}
|
|
1936
|
+
// setup vue-devtools plugin
|
|
1937
|
+
if (((process.env.NODE_ENV !== 'production') || __VUE_I18N_PROD_DEVTOOLS__) && !false) {
|
|
1938
|
+
const ret = await enableDevTools(app, i18n);
|
|
1939
|
+
if (!ret) {
|
|
1940
|
+
throw createI18nError(21 /* CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN */);
|
|
1941
|
+
}
|
|
1942
|
+
const emitter = createEmitter();
|
|
1943
|
+
if (__legacyMode) {
|
|
1944
|
+
const _vueI18n = __global;
|
|
1945
|
+
_vueI18n.__enableEmitter && _vueI18n.__enableEmitter(emitter);
|
|
1946
|
+
}
|
|
1947
|
+
else {
|
|
1948
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1949
|
+
const _composer = __global;
|
|
1950
|
+
_composer[EnableEmitter] && _composer[EnableEmitter](emitter);
|
|
1951
|
+
}
|
|
1952
|
+
emitter.on('*', addTimelineEvent);
|
|
1953
|
+
}
|
|
1954
|
+
},
|
|
1955
|
+
// global accessor
|
|
1956
|
+
get global() {
|
|
1957
|
+
return __global;
|
|
1958
|
+
},
|
|
1959
|
+
// @internal
|
|
1960
|
+
__instances,
|
|
1961
|
+
// @internal
|
|
1962
|
+
__getInstance(component) {
|
|
1963
|
+
return __instances.get(component) || null;
|
|
1964
|
+
},
|
|
1965
|
+
// @internal
|
|
1966
|
+
__setInstance(component, instance) {
|
|
1967
|
+
__instances.set(component, instance);
|
|
1968
|
+
},
|
|
1969
|
+
// @internal
|
|
1970
|
+
__deleteInstance(component) {
|
|
1971
|
+
__instances.delete(component);
|
|
1972
|
+
}
|
|
1973
|
+
};
|
|
1974
|
+
return i18n;
|
|
1975
|
+
}
|
|
1976
|
+
/**
|
|
1977
|
+
* Use Composition API for Vue I18n
|
|
1978
|
+
*
|
|
1979
|
+
* @param options - An options, see {@link UseI18nOptions}
|
|
1980
|
+
*
|
|
1981
|
+
* @returns {@link Composer} instance
|
|
1982
|
+
*
|
|
1983
|
+
* @remarks
|
|
1984
|
+
* This function is mainly used by `setup`.
|
|
1985
|
+
*
|
|
1986
|
+
* If options are specified, Composer instance is created for each component and you can be localized on the component.
|
|
1987
|
+
*
|
|
1988
|
+
* If options are not specified, you can be localized using the global Composer.
|
|
1989
|
+
*
|
|
1990
|
+
* @example
|
|
1991
|
+
* case: Component resource base localization
|
|
1992
|
+
* ```html
|
|
1993
|
+
* <template>
|
|
1994
|
+
* <form>
|
|
1995
|
+
* <label>{{ t('language') }}</label>
|
|
1996
|
+
* <select v-model="locale">
|
|
1997
|
+
* <option value="en">en</option>
|
|
1998
|
+
* <option value="ja">ja</option>
|
|
1999
|
+
* </select>
|
|
2000
|
+
* </form>
|
|
2001
|
+
* <p>message: {{ t('hello') }}</p>
|
|
2002
|
+
* </template>
|
|
2003
|
+
*
|
|
2004
|
+
* <script>
|
|
2005
|
+
* import { useI18n } from 'vue-i18n'
|
|
2006
|
+
*
|
|
2007
|
+
* export default {
|
|
2008
|
+
* setup() {
|
|
2009
|
+
* const { t, locale } = useI18n({
|
|
2010
|
+
* locale: 'ja',
|
|
2011
|
+
* messages: {
|
|
2012
|
+
* en: { ... },
|
|
2013
|
+
* ja: { ... }
|
|
2014
|
+
* }
|
|
2015
|
+
* })
|
|
2016
|
+
* // Something to do ...
|
|
2017
|
+
*
|
|
2018
|
+
* return { ..., t, locale }
|
|
2019
|
+
* }
|
|
2020
|
+
* }
|
|
2021
|
+
* </script>
|
|
2022
|
+
* ```
|
|
2023
|
+
*
|
|
2024
|
+
* @VueI18nComposition
|
|
2025
|
+
*/
|
|
2026
|
+
function useI18n(options = {}) {
|
|
2027
|
+
const instance = getCurrentInstance();
|
|
2028
|
+
if (instance == null) {
|
|
2029
|
+
throw createI18nError(16 /* MUST_BE_CALL_SETUP_TOP */);
|
|
2030
|
+
}
|
|
2031
|
+
if (!instance.appContext.app.__VUE_I18N_SYMBOL__) {
|
|
2032
|
+
throw createI18nError(17 /* NOT_INSLALLED */);
|
|
2033
|
+
}
|
|
2034
|
+
const i18n = inject(instance.appContext.app.__VUE_I18N_SYMBOL__);
|
|
2035
|
+
/* istanbul ignore if */
|
|
2036
|
+
if (!i18n) {
|
|
2037
|
+
throw createI18nError(22 /* UNEXPECTED_ERROR */);
|
|
2038
|
+
}
|
|
2039
|
+
// prettier-ignore
|
|
2040
|
+
const global = i18n.mode === 'composition'
|
|
2041
|
+
? i18n.global
|
|
2042
|
+
: i18n.global.__composer;
|
|
2043
|
+
// prettier-ignore
|
|
2044
|
+
const scope = isEmptyObject(options)
|
|
2045
|
+
? ('__i18n' in instance.type)
|
|
2046
|
+
? 'local'
|
|
2047
|
+
: 'global'
|
|
2048
|
+
: !options.useScope
|
|
2049
|
+
? 'local'
|
|
2050
|
+
: options.useScope;
|
|
2051
|
+
if (scope === 'global') {
|
|
2052
|
+
let messages = isObject(options.messages) ? options.messages : {};
|
|
2053
|
+
if ('__i18nGlobal' in instance.type) {
|
|
2054
|
+
messages = getLocaleMessages(global.locale.value, {
|
|
2055
|
+
messages,
|
|
2056
|
+
__i18n: instance.type.__i18nGlobal
|
|
2057
|
+
});
|
|
2058
|
+
}
|
|
2059
|
+
// merge locale messages
|
|
2060
|
+
const locales = Object.keys(messages);
|
|
2061
|
+
if (locales.length) {
|
|
2062
|
+
locales.forEach(locale => {
|
|
2063
|
+
global.mergeLocaleMessage(locale, messages[locale]);
|
|
2064
|
+
});
|
|
2065
|
+
}
|
|
2066
|
+
// merge datetime formats
|
|
2067
|
+
if (isObject(options.datetimeFormats)) {
|
|
2068
|
+
const locales = Object.keys(options.datetimeFormats);
|
|
2069
|
+
if (locales.length) {
|
|
2070
|
+
locales.forEach(locale => {
|
|
2071
|
+
global.mergeDateTimeFormat(locale, options.datetimeFormats[locale]);
|
|
2072
|
+
});
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
// merge number formats
|
|
2076
|
+
if (isObject(options.numberFormats)) {
|
|
2077
|
+
const locales = Object.keys(options.numberFormats);
|
|
2078
|
+
if (locales.length) {
|
|
2079
|
+
locales.forEach(locale => {
|
|
2080
|
+
global.mergeNumberFormat(locale, options.numberFormats[locale]);
|
|
2081
|
+
});
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
return global;
|
|
2085
|
+
}
|
|
2086
|
+
if (scope === 'parent') {
|
|
2087
|
+
let composer = getComposer(i18n, instance);
|
|
2088
|
+
if (composer == null) {
|
|
2089
|
+
if ((process.env.NODE_ENV !== 'production')) {
|
|
2090
|
+
warn(getWarnMessage(12 /* NOT_FOUND_PARENT_SCOPE */));
|
|
2091
|
+
}
|
|
2092
|
+
composer = global;
|
|
2093
|
+
}
|
|
2094
|
+
return composer;
|
|
2095
|
+
}
|
|
2096
|
+
// scope 'local' case
|
|
2097
|
+
if (i18n.mode === 'legacy') {
|
|
2098
|
+
throw createI18nError(18 /* NOT_AVAILABLE_IN_LEGACY_MODE */);
|
|
2099
|
+
}
|
|
2100
|
+
const i18nInternal = i18n;
|
|
2101
|
+
let composer = i18nInternal.__getInstance(instance);
|
|
2102
|
+
if (composer == null) {
|
|
2103
|
+
const type = instance.type;
|
|
2104
|
+
const composerOptions = assign({}, options);
|
|
2105
|
+
if (type.__i18n) {
|
|
2106
|
+
composerOptions.__i18n = type.__i18n;
|
|
2107
|
+
}
|
|
2108
|
+
if (global) {
|
|
2109
|
+
composerOptions.__root = global;
|
|
2110
|
+
}
|
|
2111
|
+
composer = createComposer(composerOptions);
|
|
2112
|
+
setupLifeCycle(i18nInternal, instance, composer);
|
|
2113
|
+
i18nInternal.__setInstance(instance, composer);
|
|
2114
|
+
}
|
|
2115
|
+
return composer;
|
|
2116
|
+
}
|
|
2117
|
+
function getComposer(i18n, target) {
|
|
2118
|
+
let composer = null;
|
|
2119
|
+
const root = target.root;
|
|
2120
|
+
let current = target.parent;
|
|
2121
|
+
while (current != null) {
|
|
2122
|
+
const i18nInternal = i18n;
|
|
2123
|
+
if (i18n.mode === 'composition') {
|
|
2124
|
+
composer = i18nInternal.__getInstance(current);
|
|
2125
|
+
}
|
|
2126
|
+
else {
|
|
2127
|
+
const vueI18n = i18nInternal.__getInstance(current);
|
|
2128
|
+
if (vueI18n != null) {
|
|
2129
|
+
composer = vueI18n
|
|
2130
|
+
.__composer;
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
if (composer != null) {
|
|
2134
|
+
break;
|
|
2135
|
+
}
|
|
2136
|
+
if (root === current) {
|
|
2137
|
+
break;
|
|
2138
|
+
}
|
|
2139
|
+
current = current.parent;
|
|
2140
|
+
}
|
|
2141
|
+
return composer;
|
|
2142
|
+
}
|
|
2143
|
+
function setupLifeCycle(i18n, target, composer) {
|
|
2144
|
+
let emitter = null;
|
|
2145
|
+
onMounted(() => {
|
|
2146
|
+
// inject composer instance to DOM for intlify-devtools
|
|
2147
|
+
if (((process.env.NODE_ENV !== 'production') || __VUE_I18N_PROD_DEVTOOLS__) &&
|
|
2148
|
+
!false &&
|
|
2149
|
+
target.vnode.el) {
|
|
2150
|
+
target.vnode.el.__VUE_I18N__ = composer;
|
|
2151
|
+
emitter = createEmitter();
|
|
2152
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2153
|
+
const _composer = composer;
|
|
2154
|
+
_composer[EnableEmitter] && _composer[EnableEmitter](emitter);
|
|
2155
|
+
emitter.on('*', addTimelineEvent);
|
|
2156
|
+
}
|
|
2157
|
+
}, target);
|
|
2158
|
+
onUnmounted(() => {
|
|
2159
|
+
// remove composer instance from DOM for intlify-devtools
|
|
2160
|
+
if (((process.env.NODE_ENV !== 'production') || __VUE_I18N_PROD_DEVTOOLS__) &&
|
|
2161
|
+
!false &&
|
|
2162
|
+
target.vnode.el &&
|
|
2163
|
+
target.vnode.el.__VUE_I18N__) {
|
|
2164
|
+
emitter && emitter.off('*', addTimelineEvent);
|
|
2165
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2166
|
+
const _composer = composer;
|
|
2167
|
+
_composer[DisableEmitter] && _composer[DisableEmitter]();
|
|
2168
|
+
delete target.vnode.el.__VUE_I18N__;
|
|
2169
|
+
}
|
|
2170
|
+
i18n.__deleteInstance(target);
|
|
2171
|
+
}, target);
|
|
2172
|
+
}
|
|
2173
|
+
const globalExportProps = [
|
|
2174
|
+
'locale',
|
|
2175
|
+
'fallbackLocale',
|
|
2176
|
+
'availableLocales'
|
|
2177
|
+
];
|
|
2178
|
+
const globalExportMethods = ['t', 'rt', 'd', 'n', 'tm'];
|
|
2179
|
+
function injectGlobalFields(app, composer) {
|
|
2180
|
+
const i18n = Object.create(null);
|
|
2181
|
+
globalExportProps.forEach(prop => {
|
|
2182
|
+
const desc = Object.getOwnPropertyDescriptor(composer, prop);
|
|
2183
|
+
if (!desc) {
|
|
2184
|
+
throw createI18nError(22 /* UNEXPECTED_ERROR */);
|
|
2185
|
+
}
|
|
2186
|
+
const wrap = isRef(desc.value) // check computed props
|
|
2187
|
+
? {
|
|
2188
|
+
get() {
|
|
2189
|
+
return desc.value.value;
|
|
2190
|
+
},
|
|
2191
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2192
|
+
set(val) {
|
|
2193
|
+
desc.value.value = val;
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
: {
|
|
2197
|
+
get() {
|
|
2198
|
+
return desc.get && desc.get();
|
|
2199
|
+
}
|
|
2200
|
+
};
|
|
2201
|
+
Object.defineProperty(i18n, prop, wrap);
|
|
2202
|
+
});
|
|
2203
|
+
app.config.globalProperties.$i18n = i18n;
|
|
2204
|
+
globalExportMethods.forEach(method => {
|
|
2205
|
+
const desc = Object.getOwnPropertyDescriptor(composer, method);
|
|
2206
|
+
if (!desc || !desc.value) {
|
|
2207
|
+
throw createI18nError(22 /* UNEXPECTED_ERROR */);
|
|
2208
|
+
}
|
|
2209
|
+
Object.defineProperty(app.config.globalProperties, `$${method}`, desc);
|
|
2210
|
+
});
|
|
2211
|
+
}
|
|
2212
|
+
|
|
2213
|
+
{
|
|
2214
|
+
initFeatureFlags();
|
|
2215
|
+
}
|
|
2216
|
+
// NOTE: experimental !!
|
|
2217
|
+
if ((process.env.NODE_ENV !== 'production') || __INTLIFY_PROD_DEVTOOLS__) {
|
|
2218
|
+
const target = getGlobalThis();
|
|
2219
|
+
target.__INTLIFY__ = true;
|
|
2220
|
+
setDevToolsHook(target.__INTLIFY_DEVTOOLS_GLOBAL_HOOK__);
|
|
2221
|
+
}
|
|
2222
|
+
if ((process.env.NODE_ENV !== 'production')) ;
|
|
2223
|
+
|
|
2224
|
+
export { DatetimeFormat, NumberFormat, Translation, VERSION, createI18n, useI18n, vTDirective };
|