Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: merging of locale files with the same name for @intlify/unplugin-vue-i18n/messages #274

Merged
merged 3 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/unplugin-vue-i18n/examples/vite/src/locales/en.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
select: Do you want banana?
fruits:
banana: 'no bananas | {n} banana | {n} bananas'
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fruits:
banana: 'no bananas | {n} banana | {n} bananas'
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
fruits: {
banana: 'バナナがない | バナナ {n} 個'
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
select: "バナナが欲しい?",
fruits: {
banana: "バナナがない | バナナ {n} 個"
}
select: 'バナナが欲しい?'
}
9 changes: 2 additions & 7 deletions packages/unplugin-vue-i18n/examples/vite/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { createApp } from 'vue'
import { createI18n } from 'vue-i18n'
import App from './App.vue'
import ja from './locales/ja.json5'
import en from './locales/en.yaml'
// import messages from '@intlify/vite-plugin-vue-i18n/messages'
import messages from '@intlify/unplugin-vue-i18n/messages'

const i18n = createI18n({
legacy: false,
locale: 'ja',
messages: {
ja,
en
}
messages
})

const app = createApp(App)
Expand Down
1 change: 1 addition & 0 deletions packages/unplugin-vue-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"fast-glob": "^3.2.12",
"js-yaml": "^4.1.0",
"json5": "^2.2.3",
"lodash.merge": "^4.6.2",
"pathe": "^1.0.0",
"picocolors": "^1.0.0",
"source-map": "0.6.1",
Expand Down
8 changes: 5 additions & 3 deletions packages/unplugin-vue-i18n/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,9 +703,11 @@ async function generateBundleResources(
}
}

return `export default {
${codes.join(`,\n`)}
}`
return `import merge from 'lodash.merge'

export default merge({},
${codes.map(code => `{${code}}`).join(',\n')}
)`
}

async function getCode(
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,7 @@ __metadata:
fast-glob: ^3.2.12
js-yaml: ^4.1.0
json5: ^2.2.3
lodash.merge: ^4.6.2
pathe: ^1.0.0
picocolors: ^1.0.0
source-map: 0.6.1
Expand Down