Skip to content

Commit cbbf632

Browse files
authored
fix(unplugin-vue-i18n): exclude locales when using mixed locales #329 (#366)
1 parent 68f63aa commit cbbf632

File tree

6 files changed

+282
-54
lines changed

6 files changed

+282
-54
lines changed

packages/bundle-utils/src/json.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ export function generate(
6565
escapeHtml,
6666
jit
6767
} as CodeGenOptions
68-
const generator = createCodeGenerator(options)
6968

7069
let ast = parseJSON(value, { filePath: filename })
7170

@@ -81,6 +80,14 @@ export function generate(
8180
ast = parseJSON(value, { filePath: filename })
8281
}
8382

83+
if (locale && onlyLocales?.length && !onlyLocales.includes(locale)) {
84+
value = JSON.stringify({})
85+
ast = parseJSON(value, { filePath: filename })
86+
options.locale = ''
87+
options.source = undefined
88+
}
89+
90+
const generator = createCodeGenerator(options)
8491
const codeMaps = _generate(generator, ast, options)
8592

8693
const { code, map } = generator.context()

packages/bundle-utils/src/yaml.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ export function generate(
6565
escapeHtml,
6666
jit
6767
} as CodeGenOptions
68-
const generator = createCodeGenerator(options)
6968

7069
let ast = parseYAML(value, { filePath: filename })
7170

@@ -81,6 +80,14 @@ export function generate(
8180
ast = parseYAML(value, { filePath: filename })
8281
}
8382

83+
if (locale && onlyLocales?.length && !onlyLocales.includes(locale)) {
84+
value = JSON.stringify({})
85+
ast = parseYAML(value, { filePath: filename })
86+
options.locale = ''
87+
options.source = undefined
88+
}
89+
90+
const generator = createCodeGenerator(options)
8491
const codeMaps = _generate(generator, ast, options)
8592

8693
const { code, map } = generator.context()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<i18n lang="json">
2+
{
3+
"en": {
4+
"hello": "hello world!"
5+
}
6+
}
7+
</i18n>
8+
9+
<i18n locale="ja" lang="json">
10+
{
11+
"hello": "こんにちは、世界!"
12+
}
13+
</i18n>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<i18n lang="yaml">
2+
en:
3+
hello: hello world!
4+
</i18n>
5+
6+
<i18n locale="ja" lang="yaml">
7+
hello: こんにちは、世界!
8+
</i18n>

0 commit comments

Comments
 (0)