Skip to content

Commit

Permalink
fix: layer VueI18n configuration should not deep copy primitives (#2376)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbieGoede authored Sep 5, 2023
1 parent b25d63f commit 11d3c31
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions specs/fixtures/layer_consumer/i18n.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default {
fallbackLocale: 'nl',
messages: {
nl: {
about: 'Over deze site',
Expand Down
4 changes: 3 additions & 1 deletion specs/fixtures/layer_consumer/layer-simple/i18n.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
export default {
fallbackLocale: 'en',
messages: {
fr: {
thanks: 'Merci!',
about: 'Should be overridden'
},
nl: {
thanks: 'Bedankt!'
thanks: 'Bedankt!',
uniqueTranslation: 'Unieke vertaling'
},
en: {
about: 'About this site',
Expand Down
1 change: 1 addition & 0 deletions specs/fixtures/layer_consumer/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ useHead({
<div id="layer-message">{{ $t('thanks') }}</div>
<div id="snake-case">{{ $t('snakeCaseText') }}</div>
<div id="pascal-case">{{ $t('pascalCaseText') }}</div>
<div id="fallback-message">{{ $t('uniqueTranslation') }}</div>
<LangSwitcher />
<section>
<strong><code>useHead</code> with <code>useLocaleHead</code></strong
Expand Down
2 changes: 2 additions & 0 deletions specs/layers/layers_vuei18n_options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ describe('nuxt layers vuei18n options', async () => {
await page.click(`#set-locale-link-en`)
expect(await getText(page, '#snake-case')).toEqual('About-this-site')
expect(await getText(page, '#pascal-case')).toEqual('AboutThisSite')
expect(await getText(page, '#fallback-message')).toEqual('Unieke vertaling')

await page.click(`#set-locale-link-fr`)
expect(await getText(page, '#snake-case')).toEqual('À-propos-de-ce-site')
expect(await getText(page, '#pascal-case')).toEqual('ÀProposDeCeSite')
expect(await getText(page, '#fallback-message')).toEqual('Unieke vertaling')
})
})
2 changes: 1 addition & 1 deletion src/gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export function generateLoaderOptions(
const skipped = ['messages']
for (const [k, v] of Object.entries(cfg).filter(([k]) => !skipped.includes(k))) {
if(nuxtI18nOptions.vueI18n?.[k] === undefined) {
if(nuxtI18nOptions.vueI18n?.[k] === undefined || typeof nuxtI18nOptions.vueI18n?.[k] !== 'object') {
nuxtI18nOptions.vueI18n[k] = v
} else {
deepCopy(v, nuxtI18nOptions.vueI18n[k])
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/gen.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export const resolveNuxtI18nOptions = async (context) => {
const skipped = ['messages']
for (const [k, v] of Object.entries(cfg).filter(([k]) => !skipped.includes(k))) {
if(nuxtI18nOptions.vueI18n?.[k] === undefined) {
if(nuxtI18nOptions.vueI18n?.[k] === undefined || typeof nuxtI18nOptions.vueI18n?.[k] !== 'object') {
nuxtI18nOptions.vueI18n[k] = v
} else {
deepCopy(v, nuxtI18nOptions.vueI18n[k])
Expand Down

0 comments on commit 11d3c31

Please sign in to comment.