Skip to content

Commit d4f753b

Browse files
committed
fix(unplugin-vue-i18n): ts files load
1 parent de5e774 commit d4f753b

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

examples/vite/src/Banana.vue

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
<template>
22
<form id="fruits">
33
<label>{{ t('select') }}</label>
4+
5+
46
<select v-model.number="select">
57
<option value="0">0</option>
68
<option value="1">1</option>
79
<option value="2">2</option>
810
<option value="3">3</option>
911
</select>
1012
</form>
13+
<form id="lang">
14+
<label>{{ t('language') }}</label>
15+
<select v-model="locale">
16+
<option value="en">en</option>
17+
<option value="ja">ja</option>
18+
</select>
19+
</form>
20+
<p id="login">{{ t('common.login') }}</p>
1121
<p id="banana">{{ t('fruits.banana', select, { n: select }) }}</p>
1222
</template>
1323

1424
<script setup lang="ts">
1525
import { ref } from 'vue'
1626
import { useI18n } from 'vue-i18n'
1727
18-
const { t } = useI18n({ useScope: 'global' })
28+
const { t,locale} = useI18n({ useScope: 'global' })
1929
const select = ref(0)
2030
</script>
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
common: {
3+
login: 'Login'
4+
}
5+
}

examples/vite/src/locales/ja.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
common: {
3+
login: 'ja Login'
4+
}
5+
}

packages/unplugin-vue-i18n/src/core/resource.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ export function resourcePlugin(
232232
},
233233

234234
async handleHotUpdate({ file, server }) {
235-
if (/\.(json5?|ya?ml)$/.test(file)) {
235+
if (/\.(json5?|ya?ml|([c|m]?js|[c|m]?ts))$/.test(file)) {
236236
const module = server.moduleGraph.getModuleById(
237237
asVirtualId(INTLIFY_BUNDLE_IMPORT_ID, meta.framework)
238238
)
@@ -540,11 +540,10 @@ async function generateBundleResources(
540540
const codes = []
541541
for (const res of resources) {
542542
debug(`${res} bundle loading ...`)
543-
544-
if (/\.(json5?|ya?ml)$/.test(res)) {
543+
if (/\.(json5?|ya?ml|([c|m]?js|[c|m]?ts))$/.test(res)) {
545544
const { ext, name } = parsePath(res)
546545
const source = await getRaw(res)
547-
const generate = /json5?/.test(ext) ? generateJSON : generateYAML
546+
const generate = getGenerator(ext)
548547
const parseOptions = getOptions(res, isProduction, {}, false, {
549548
isGlobal,
550549
jit,

0 commit comments

Comments
 (0)