Skip to content

Commit c49aae7

Browse files
authored
feat: optimizeTranslationDirective option (#377)
* refactor: drop legacy code * refactor: extract options resolving * docs: add `enableSsrTranslationDirective` option * refactor: extract resource logic as plugin * update option name * fix: update deps * fix: vue3 first class * fix: implementation * fix: add raise error for webpack * fix: remove unnecesary hmr codes
1 parent d6c4e4d commit c49aae7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2329
-1003
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ examples/**/dist
1717
.yarn/*
1818
!.yarn/releases
1919
!.yarn/plugins
20+
*.tgz

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"@types/webpack-merge": "^5.0.0",
4848
"@typescript-eslint/eslint-plugin": "^6.21.0",
4949
"@typescript-eslint/parser": "^6.21.0",
50-
"@vitejs/plugin-vue": "^1.2.5",
50+
"@vitejs/plugin-vue": "^5.0.5",
5151
"@vue/compiler-sfc": "^3.2.23",
5252
"babel-loader": "^8.2.2",
5353
"chalk": "^4.1.1",
@@ -82,13 +82,13 @@
8282
"typescript": "^4.9.3",
8383
"vite": "^4.4.9",
8484
"vitest": "^0.29.8",
85-
"vue": "^2.6.14",
85+
"vue": "^3.2.25",
8686
"vue-i18n": "next",
8787
"vue-loader": "^16.3.0",
8888
"vue-loader15": "npm:[email protected]",
8989
"vue-loader17": "npm:[email protected]",
9090
"vue-template-compiler": "^2.6.14",
91-
"vue3": "npm:vue@3.3.4",
91+
"vue2": "npm:vue@^2.6.14",
9292
"webpack": "^5.88.2",
9393
"webpack-cli": "^5.1.4",
9494
"webpack-dev-server": "^4.15.1",

packages/rollup-plugin-vue-i18n/examples/rollup.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default [
2525
entries: {
2626
vue: path.resolve(
2727
__dirname,
28-
'../../../node_modules/vue3/dist/vue.esm-bundler.js'
28+
'../../../node_modules/vue/dist/vue.esm-bundler.js'
2929
)
3030
}
3131
}),

packages/unplugin-vue-i18n/README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ Whether to tree-shake message compiler when we will be bundling.
374374

375375
If do you will use this option, you need to enable `jitCompilation` option.
376376

377-
> [NOTE]
377+
> [!NOTE]
378378
> After v5 or later, this option can be set with or without `jitCompilation`.
379379
380380
> [!NOTE]
@@ -571,6 +571,18 @@ If do you will use this option, you need to enable `jitCompilation` option.
571571
`useVueI18nImportName` option is deprecated in v5.
572572
This option will be supported with vue-i18n until v9 latest version.
573573

574+
### `optimizeTranslationDirective`
575+
576+
- **Type**: `boolean` | `string` | `string[]`
577+
- **Default:** `false`
578+
579+
Whether to optimize `v-t` directive. If set to `true`, this plugin's transform will automatically translate to vue-i18n's translation function. If you need SSR, you must activate this option.
580+
581+
If you want to put it manually, you can specify the signature of the translation function as a string or a string array.
582+
583+
> [!WARNING]
584+
About for manually signature, see the details [vue-i18n-extensions API docs](https://github.com/intlify/vue-i18n-extensions/blob/next/docs/%40intlify/vue-i18n-extensions-api.md#translationsignatures) and [usecase from vue-i18n-extensions PR](https://github.com/intlify/vue-i18n-extensions/pull/217/files#diff-3fb9543f91e011d4b0dc9beff44082fe1a99c9eab70c1afab23c3c34352b7c38R121-R200)
585+
574586
## 📜 Changelog
575587

576588
Details changes for each release are documented in the [CHANGELOG.md](https://github.com/intlify/bundle-tools/blob/main/packages/unplugin-vue-i18n/CHANGELOG.md)

packages/unplugin-vue-i18n/e2e/vite.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ describe('vite', () => {
88
await expect(page).toMatch('こんにちは、世界!')
99
await expect(page).toMatch('バナナが欲しい?')
1010
await expect(page).toMatch('バナナ 0 個')
11+
await expect(page).toMatch('やあ!')
1112
})
1213

1314
test('change locale', async () => {
1415
await page.select('#app select', 'en')
1516
await expect(page).toMatch('Language')
1617
await expect(page).toMatch('hello, world!')
18+
await expect(page).toMatch('Hi!')
1719
})
1820

1921
test('change banana select', async () => {

packages/unplugin-vue-i18n/examples/vite/src/App.vue

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
</select>
88
</form>
99
<p>{{ t('hello') }}</p>
10+
<p v-t="'hi'"></p>
1011
<Banana />
1112
</template>
1213

@@ -29,15 +30,17 @@ export default {
2930
}
3031
</script>
3132

32-
<i18n>
33+
<i18n lang="json">
3334
{
3435
"en": {
3536
"language": "Language",
36-
"hello": "hello, world!"
37+
"hello": "hello, world!",
38+
"hi": "Hi!"
3739
},
3840
"ja": {
3941
"language": "言語",
40-
"hello": "こんにちは、世界!"
42+
"hello": "こんにちは、世界!",
43+
"hi": "やあ!"
4144
}
4245
}
4346
</i18n>

packages/unplugin-vue-i18n/examples/vite/vite.config.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default defineConfig({
88
alias: {
99
vue: path.resolve(
1010
__dirname,
11-
'../../../../node_modules/vue3/dist/vue.esm-bundler.js'
11+
'../../../../node_modules/vue/dist/vue.esm-bundler.js'
1212
)
1313
}
1414
},
@@ -20,7 +20,8 @@ export default defineConfig({
2020
plugins: [
2121
vue(),
2222
vueI18n({
23-
include: path.resolve(__dirname, './src/locales/**')
23+
include: path.resolve(__dirname, './src/locales/**'),
24+
optimizeTranslationDirective: true
2425
})
2526
]
2627
})

packages/unplugin-vue-i18n/package.json

+8-7
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,34 @@
1111
},
1212
"peerDependencies": {
1313
"petite-vue-i18n": "*",
14-
"vue-i18n": "*",
15-
"vue-i18n-bridge": "*"
14+
"vue": "^3.2.25",
15+
"vue-i18n": "*"
1616
},
1717
"peerDependenciesMeta": {
1818
"petite-vue-i18n": {
1919
"optional": true
2020
},
2121
"vue-i18n": {
2222
"optional": true
23-
},
24-
"vue-i18n-bridge": {
25-
"optional": true
2623
}
2724
},
2825
"dependencies": {
26+
"@eslint-community/eslint-utils": "^4.4.0",
2927
"@intlify/bundle-utils": "^9.0.0-beta.0",
3028
"@intlify/shared": "next",
29+
"@intlify/vue-i18n-extensions": "^6.2.0",
3130
"@rollup/pluginutils": "^5.1.0",
32-
"@vue/compiler-sfc": "^3.2.47",
31+
"@typescript-eslint/scope-manager": "^7.13.0",
32+
"@typescript-eslint/typescript-estree": "^7.13.0",
3333
"debug": "^4.3.3",
3434
"fast-glob": "^3.2.12",
3535
"js-yaml": "^4.1.0",
3636
"json5": "^2.2.3",
3737
"pathe": "^1.0.0",
3838
"picocolors": "^1.0.0",
3939
"source-map-js": "^1.0.2",
40-
"unplugin": "^1.1.0"
40+
"unplugin": "^1.1.0",
41+
"vue": "^3.4"
4142
},
4243
"devDependencies": {
4344
"unbuild": "^2.0.0"

0 commit comments

Comments
 (0)