Skip to content

Commit

Permalink
fix!: restructureDir defaults (#3106)
Browse files Browse the repository at this point in the history
* fix!: `restructureDir` defaults

* docs: document disabling  `restructureDir`

* fix: `restructureDir` type description

* fix: remove console log

* chore: fix playground config
  • Loading branch information
BobbieGoede authored Sep 17, 2024
1 parent 73f6b99 commit 3e33699
Show file tree
Hide file tree
Showing 30 changed files with 465 additions and 123 deletions.
2 changes: 2 additions & 0 deletions docs/content/docs/5.v9/2.guide/19.breaking-changes-in-v9.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Reasons for change
1. Context - i18n files are used both server-side and client-side, using a dedicated `i18n/` folder in the root directory outside `app/` and `server/` makes more sense.
2. Clean - less clutter/fragmentation of i18n files, and should make resolving and loading files easier for us.

To ease the migration to v9 you can disable this feature by setting `restructureDir: false`, this will be removed in v10.

## Locale `iso` renamed to `language`

The `iso` property on a locale object has been renamed to `language` to be consistent with the usage of Language Tags on the web (e.g. `navigator.language` and `Accept-Language`). The original `iso` property name referred to ISO standards which describe valid Language Tags, see the [related issue](https://github.com/nuxt-modules/i18n/issues/2449) for more details.
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"@intlify/unplugin-vue-i18n": "^5.0.0",
"@intlify/utils": "^0.13.0",
"@miyaneee/rollup-plugin-json5": "^1.2.0",
"@nuxt/kit": "^3.13.1",
"@nuxt/kit": "^3.13.2",
"@rollup/plugin-yaml": "^4.1.2",
"@vue/compiler-sfc": "^3.5.5",
"debug": "^4.3.5",
Expand All @@ -115,7 +115,7 @@
"@babel/types": "^7.24.7",
"@eslint/js": "9.5.0",
"@nuxt/module-builder": "^0.8.4",
"@nuxt/schema": "^3.13.1",
"@nuxt/schema": "^3.13.2",
"@types/debug": "^4.1.9",
"@types/eslint": "^8.56.6",
"@unhead/vue": "^1.8.8",
Expand All @@ -134,7 +134,7 @@
"lint-staged": "^15.2.7",
"nitropack": "^2.9.7",
"npm-run-all2": "^6.2.0",
"nuxt": "^3.13.1",
"nuxt": "^3.13.2",
"ofetch": "^1.3.4",
"pkg-pr-new": "^0.0.20",
"playwright-core": "^1.45.3",
Expand Down
1 change: 1 addition & 0 deletions playground/layers/i18n-layer/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
export default defineNuxtConfig({
modules: ['@nuxtjs/i18n'],
i18n: {
restructureDir: false,
langDir: 'locales',
lazy: true,
baseUrl: 'http://localhost:3000',
Expand Down
1 change: 1 addition & 0 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export default defineNuxtConfig({
// },
// debug: true,
i18n: {
restructureDir: false,
experimental: {
localeDetector: './localeDetector.ts',
switchLocalePathLinkSSR: true,
Expand Down
544 changes: 429 additions & 115 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions specs/fixtures/basic/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default defineNuxtConfig({
modules: [CustomModule, '@nuxtjs/i18n'],

i18n: {
restructureDir: false,
lazy: false,
baseUrl: 'http://localhost:3000',
locales: [
Expand Down
1 change: 1 addition & 0 deletions specs/fixtures/basic_usage/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default defineNuxtConfig({
],
plugins: [`../plugins/i18nHooks.ts`],
i18n: {
restructureDir: false,
vueI18n: './config/i18n.config.ts',
locales: ['en', 'fr'],
defaultLocale: 'en',
Expand Down
1 change: 1 addition & 0 deletions specs/fixtures/basic_usage_compat_4/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default defineNuxtConfig({
],
plugins: [`../plugins/i18nHooks.ts`],
i18n: {
restructureDir: false,
vueI18n: './config/i18n.config.ts',
defaultLocale: 'en',
experimental: {
Expand Down
1 change: 1 addition & 0 deletions specs/fixtures/different_domains/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default defineNuxtConfig({
modules: [CustomModule, '@nuxtjs/i18n'],

i18n: {
restructureDir: false,
lazy: false,
locales: [
{
Expand Down
1 change: 1 addition & 0 deletions specs/fixtures/inline_options/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default defineNuxtConfig({
],
debug: false,
i18n: {
restructureDir: false,
locales: [
{
code: 'ja',
Expand Down
1 change: 1 addition & 0 deletions specs/fixtures/issues/1888/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
export default defineNuxtConfig({
modules: ['@nuxtjs/i18n'],
i18n: {
restructureDir: false,
locales: [
{
code: 'en',
Expand Down
1 change: 1 addition & 0 deletions specs/fixtures/issues/2151/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default defineNuxtConfig({
},
modules: ['@nuxtjs/i18n'],
i18n: {
restructureDir: false,
lazy: true,
langDir: 'locales',
locales: [
Expand Down
1 change: 1 addition & 0 deletions specs/fixtures/issues/2220/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import locales from './locales'
export default defineNuxtConfig({
modules: ['@nuxtjs/i18n'],
i18n: {
restructureDir: false,
lazy: true,
langDir: 'locales',
locales,
Expand Down
1 change: 1 addition & 0 deletions specs/fixtures/issues/2226/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export default defineNuxtConfig({
modules: ['@nuxtjs/i18n'],
i18n: {
restructureDir: false,
locales: ['en', 'de'],
defaultLocale: 'en',
strategy: 'prefix_and_default'
Expand Down
1 change: 1 addition & 0 deletions specs/fixtures/issues/2247/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
export default defineNuxtConfig({
modules: ['@nuxtjs/i18n'],
i18n: {
restructureDir: false,
baseUrl: 'https://abwaab.com',
locales: [
{
Expand Down
1 change: 1 addition & 0 deletions specs/fixtures/issues/2288/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
export default defineNuxtConfig({
modules: ['@nuxtjs/i18n'],
i18n: {
restructureDir: false,
baseUrl: 'https://abwaab.com',
locales: [
{
Expand Down
1 change: 1 addition & 0 deletions specs/fixtures/issues/2315/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
export default defineNuxtConfig({
modules: ['@nuxtjs/i18n'],
i18n: {
restructureDir: false,
bundle: {
compositionOnly: false
},
Expand Down
1 change: 1 addition & 0 deletions specs/fixtures/layers/layer-domain/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// https://nuxt.com/docs/guide/directory-structure/nuxt.config
export default defineNuxtConfig({
i18n: {
restructureDir: false,
// lazy: false,
// differentDomains: true,
// defaultLocale: 'en',
Expand Down
1 change: 1 addition & 0 deletions specs/fixtures/layers/layer-lazy/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// https://nuxt.com/docs/guide/directory-structure/nuxt.config
export default defineNuxtConfig({
i18n: {
restructureDir: false,
langDir: 'locales',
locales: [
{
Expand Down
1 change: 1 addition & 0 deletions specs/fixtures/layers/layer-locale-arabic/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// https://nuxt.com/docs/guide/directory-structure/nuxt.config
export default defineNuxtConfig({
i18n: {
restructureDir: false,
langDir: 'locales',
locales: [
{
Expand Down
1 change: 1 addition & 0 deletions specs/fixtures/layers/layer-server/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// https://nuxt.com/docs/guide/directory-structure/nuxt.config
export default defineNuxtConfig({
i18n: {
restructureDir: false,
experimental: {
localeDetector: './localeDetector.ts'
},
Expand Down
1 change: 1 addition & 0 deletions specs/fixtures/layers/layer-simple/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// https://nuxt.com/docs/guide/directory-structure/nuxt.config
export default defineNuxtConfig({
i18n: {
restructureDir: false,
locales: ['fr', 'nl']
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
export default defineNuxtConfig({
modules: ['@nuxtjs/i18n'],
i18n: {
restructureDir: false,
locales: ['fr', 'nl', 'en'],
defaultLocale: 'nl',
detectBrowserLanguage: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
export default defineNuxtConfig({
modules: ['@nuxtjs/i18n'],
i18n: {
restructureDir: false,
locales: ['fr', 'nl', 'en'],
defaultLocale: 'nl',
detectBrowserLanguage: false,
Expand Down
1 change: 1 addition & 0 deletions specs/fixtures/lazy/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default defineNuxtConfig({
},
modules: [i18nModule, '@nuxtjs/i18n'],
i18n: {
restructureDir: false,
baseUrl: 'http://localhost:3000',
// langDir: 'lang',
// defaultLocale: 'fr',
Expand Down
1 change: 1 addition & 0 deletions specs/fixtures/multi_domains_locales/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default defineNuxtConfig({
modules: [CustomModule, '@nuxtjs/i18n'],

i18n: {
restructureDir: false,
lazy: false,
baseUrl: 'http://localhost:3000',
locales: [
Expand Down
1 change: 1 addition & 0 deletions specs/fixtures/restructure/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default defineNuxtConfig({
modules: [i18nModule, '@nuxtjs/i18n'],

i18n: {
restructureDir: false,
baseUrl: 'http://localhost:3000',
// langDir: 'lang',
// defaultLocale: 'fr',
Expand Down
1 change: 1 addition & 0 deletions specs/fixtures/routing/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export default defineNuxtConfig({
modules: ['@nuxtjs/i18n'],

i18n: {
restructureDir: false,
locales: ['en', 'ja'],
detectBrowserLanguage: false
}
Expand Down
5 changes: 3 additions & 2 deletions src/layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ export function resolveI18nDir(layer: NuxtConfigLayer, i18n: NuxtI18nOptions, fr
}

export function resolveLayerLangDir(layer: NuxtConfigLayer, i18n: NuxtI18nOptions) {
const langDir = i18n.langDir ?? (i18n.restructureDir ? 'locales' : '')
return resolve(resolveI18nDir(layer, i18n), langDir)
i18n.restructureDir ??= 'i18n'
i18n.langDir ??= i18n.restructureDir !== false ? 'locales' : ''
return resolve(resolveI18nDir(layer, i18n), i18n.langDir)
}

const mergeLayerLocales = (options: NuxtI18nOptions, nuxt: Nuxt) => {
Expand Down
6 changes: 3 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ export type NuxtI18nOptions<
vueI18n?: string
experimental?: ExperimentalFeatures
/**
* This can be set to a directory name to opt into the directory restructure for v9 which will have a default of 'i18n'.
* The directory to resolve i18n files from, the restructure can be disabled by setting this to `false`.
*
* @defaultValue `undefined` (v8) or `'i18n'` (v9 release)
* @defaultValue `'i18n'`
*/
restructureDir?: string
restructureDir?: string | false
bundle?: BundleOptions
compilation?: LocaleMessageCompilationOptions
customBlocks?: CustomBlocksOptions
Expand Down

0 comments on commit 3e33699

Please sign in to comment.