-
Notifications
You must be signed in to change notification settings - Fork 463
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
refactor!: read vue-i18n options from config path #1948
Changes from 5 commits
baab8be
969e60d
e380f08
8acf162
56ad478
9da8fe7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,26 +6,37 @@ Related Vue I18n options. | |
|
||
## `vueI18n` | ||
|
||
- type: `object` or `string` | ||
- default: `{}` | ||
|
||
Configuration for the `vue-i18n` library that is used internally by this module. See full documentation at https://vue-i18n.intlify.dev/api/general.html#createi18n | ||
|
||
::alert{type="info"} | ||
|
||
It's also supported to set this property to a path to a local configuration file. The file needs to export a function or plain object. If a function, it will be passed a Nuxt Context as a parameter. It's necessary to use that approach when overriding more complex types (like functions) that can't be stringified correctly. | ||
|
||
```ts {}[~/vue-i18n.options.ts] | ||
import type { I18nOptions } from 'vue-i18n' | ||
import type { NuxtApp } from 'nuxt/dist/app/index' | ||
- type: `object` | ||
- default: `undefined` | ||
|
||
Build-time configuration for the `vue-i18n` options that is used internally by this module. See full documentation at https://vue-i18n.intlify.dev/api/general.html#createi18n | ||
|
||
Configuration for `createI18n` can be passed using a configuration file. By default, the module will scan for a `i18n.config.{js,mjs,ts}` if nothing is specified. | ||
|
||
```ts {}[nuxt.config.ts] | ||
export default defineNuxtConfig({ | ||
modules: [ | ||
'@nuxtjs/i18n' | ||
], | ||
i18n: { | ||
vueI18n: { configPath: './nuxt-i18n.js' } // custom path example | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, sorry, Never mind this comment. |
||
} | ||
}) | ||
``` | ||
|
||
export default function (nuxt: NuxtApp) { | ||
return { | ||
modifiers: { | ||
snakeCase: (str) => str.split(' ').join('-') | ||
```ts {}[nuxt-i18n.js] | ||
export default defineI18nConfig({ | ||
legacy: false, | ||
locale: 'en', | ||
messages: { | ||
en: { | ||
welcome: 'Welcome' | ||
}, | ||
fr: { | ||
welcome: 'Bienvenue' | ||
} | ||
} as I18nOptions | ||
} | ||
} | ||
}) | ||
``` | ||
|
||
:: | ||
|
@@ -34,6 +45,6 @@ export default function (nuxt: NuxtApp) { | |
|
||
The `messages` option cannot be included in an object and exported with function due to limitations in Vue I18n v9 handling of locale messages. | ||
|
||
As the workaround, you can use [lazy-load transtions](/guide/lazy-load-translations) in Nuxt i18n module. locale messages handled with lazy-load transtions will be loaded as locale messges inside Vue i18n. | ||
As the workaround, you can use [lazy-load transtions](/guide/lazy-load-translations) in Nuxt i18n module. locale messages handled with lazy-load transtions will be loaded as locale messages inside Vue i18n. | ||
|
||
:: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// import { defineI18nConfig, type I18nOptions } from '@nuxtjs/i18n' | ||
|
||
// export default <I18nOptions>{ | ||
export default defineI18nConfig({ | ||
legacy: false, | ||
locale: 'en', | ||
fallbackLocale: 'fr' | ||
// messages: { | ||
// ja: { | ||
// hello: 'γγγ«γ‘γ―οΌ' | ||
// } | ||
// } | ||
// fallbackLocale: { | ||
// en: ['ja', 'fr', 'en-US'], | ||
// ja: ['en', 'fr', 'ja-JP'], | ||
// fr: ['en', 'ja', 'fr-FR'] | ||
// } | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should name
defineIVue18nConfig
, notdefineI18nConfig
, because that is coniguration forvueI18n
option. And some people might misunderstand it as a nuxt i18n setting.