Skip to content

Commit

Permalink
fix: local scope on legacy API mode (#2319)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon authored Aug 16, 2023
1 parent 81f5d69 commit 10ec68d
Show file tree
Hide file tree
Showing 15 changed files with 173 additions and 59 deletions.
14 changes: 13 additions & 1 deletion docs/content/3.options/6.misc.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ Supported properties:
- `jsTsFormatResource` (default: `false`) - Allow the format `js` and `ts` for locale messages in lazy load translation.


## `bundle`

- type: `object`
- default: `{ compositionOnly: true }`

Configure the bundling optimization for nuxt i18n module.

Supported properties:

- `compositionOnly` (default: `true`) - Whether to make vue-i18n API only composition API. By default the legacy API is tree-shaken. For more details, See [here](https://vue-i18n.intlify.dev/guide/advanced/optimization.html#reduce-bundle-size-with-feature-build-flags)


## `compilation`

- type: `object`
Expand Down Expand Up @@ -89,4 +101,4 @@ Don't enable this option for use in production. Performance will be decreased.
- type: `boolean`
- default: `false`

Set the plugin as `parallel`. See [nuxt plugin loading strategy](https://nuxt.com/docs/guide/directory-structure/plugins#loading-strategy).
Set the plugin as `parallel`. See [nuxt plugin loading strategy](https://nuxt.com/docs/guide/directory-structure/plugins#loading-strategy).
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
}
},
"dependencies": {
"@intlify/shared": "9.3.0-beta.24",
"@intlify/shared": "9.3.0-beta.26",
"@intlify/unplugin-vue-i18n": "^0.12.2",
"@mizchi/sucrase": "^4.1.0",
"@nuxt/kit": "^3.6.5",
Expand All @@ -95,8 +95,8 @@
"ufo": "^1.1.2",
"unplugin": "^1.3.2",
"unstorage": "^1.5.0",
"vue-i18n": "9.3.0-beta.24",
"vue-i18n-routing": "^0.13.2"
"vue-i18n": "9.3.0-beta.26",
"vue-i18n-routing": "^0.13.3"
},
"devDependencies": {
"@babel/parser": "^7.22.7",
Expand Down
104 changes: 56 additions & 48 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions specs/fixtures/issues/2315/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div>
<Legacy />
</div>
</template>
20 changes: 20 additions & 0 deletions specs/fixtures/issues/2315/components/Legacy.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
i18n: {
locale: 'en',
messages: {
en: {
hello: 'Hello, local!'
}
}
}
})
</script>

<template>
<p>
Legacy: <code id="msg">{{ $t('hello') }}</code>
</p>
</template>
11 changes: 11 additions & 0 deletions specs/fixtures/issues/2315/i18n.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default defineI18nConfig(() => {
return {
locale: 'en',
legacy: true,
messages: {
en: {
hello: 'Hello World!'
}
}
}
})
12 changes: 12 additions & 0 deletions specs/fixtures/issues/2315/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
modules: ['@nuxtjs/i18n'],
i18n: {
bundle: {
compositionOnly: false
},
types: 'legacy',
locales: ['en'],
defaultLocale: 'en'
}
})
14 changes: 14 additions & 0 deletions specs/fixtures/issues/2315/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "nuxt3-test-issues-2315",
"private": true,
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview"
},
"devDependencies": {
"@nuxtjs/i18n": "latest",
"nuxt": "latest"
}
}
18 changes: 18 additions & 0 deletions specs/issues/2315.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { test, expect, describe } from 'vitest'
import { fileURLToPath } from 'node:url'
import { setup, url, createPage } from '../utils'
import { getText } from '../helper'

describe('#2315', async () => {
await setup({
rootDir: fileURLToPath(new URL(`../fixtures/issues/2315`, import.meta.url))
})

test('locale scope', async () => {
const home = url('/')
const page = await createPage()
await page.goto(home)

expect(await getText(page, '#msg')).toEqual('Hello, local!')
})
})
Loading

0 comments on commit 10ec68d

Please sign in to comment.