-
-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add property
bundle.onlyLocales
(#2478)
- Loading branch information
Showing
14 changed files
with
217 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { test, expect } from 'vitest' | ||
import { fileURLToPath } from 'node:url' | ||
import { setup, url, createPage } from './utils' | ||
import { getText } from './helper' | ||
|
||
await setup({ | ||
rootDir: fileURLToPath(new URL(`./fixtures/locale_codes`, import.meta.url)), | ||
browser: true, | ||
// overrides | ||
nuxtConfig: { | ||
i18n: { | ||
bundle: { | ||
onlyLocales: 'en' | ||
} | ||
} | ||
} | ||
}) | ||
|
||
test('leave only English locale', async () => { | ||
const home = url('/') | ||
const page = await createPage() | ||
await page.goto(home) | ||
|
||
const locales = await page.locator('li') | ||
|
||
expect(await locales.count()).toEqual(1) | ||
expect(await getText(page, 'li')).toMatch('en') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<script setup lang="ts"> | ||
import { useI18n } from '#i18n' | ||
const { locales } = useI18n() | ||
</script> | ||
|
||
<template> | ||
<ul> | ||
<li v-for="locale in locales" :key="locale.code"> | ||
{{ locale.code }} | ||
</li> | ||
</ul> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default { | ||
legacy: false, | ||
fallbackLocale: 'en' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export default defineI18nConfig(() => { | ||
return { | ||
messages: { | ||
ja: { | ||
layerText: 'これはマージされたロケールキーです' | ||
} | ||
} | ||
} | ||
}) |
28 changes: 28 additions & 0 deletions
28
specs/fixtures/locale_codes/layers/i18n-layer/nuxt.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// import type { NuxtApp } from 'nuxt/dist/app/index' | ||
|
||
// https://nuxt.com/docs/guide/directory-structure/nuxt.config | ||
export default defineNuxtConfig({ | ||
modules: ['@nuxtjs/i18n'], | ||
i18n: { | ||
locales: [ | ||
{ | ||
code: 'en', | ||
iso: 'en-US', | ||
name: 'English' | ||
}, | ||
{ | ||
code: 'fr', | ||
iso: 'fr-FR', | ||
name: 'Francais' | ||
}, | ||
{ | ||
code: 'nl', | ||
iso: 'nl-NL', | ||
name: 'Nederlands' | ||
} | ||
], | ||
bundle: { | ||
onlyLocales: ['en', 'fr'] | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { defineNuxtModule } from '@nuxt/kit' | ||
|
||
export default defineNuxtModule({ | ||
async setup(options, nuxt) { | ||
nuxt.hook('i18n:registerModule', register => { | ||
register({ | ||
langDir: './lang', | ||
locales: [ | ||
{ | ||
code: 'en', | ||
iso: 'en-US', | ||
name: 'English' | ||
}, | ||
{ | ||
code: 'fr', | ||
iso: 'fr-FR', | ||
name: 'Francais' | ||
}, | ||
{ | ||
code: 'nl', | ||
iso: 'nl-NL', | ||
name: 'Nederlands' | ||
}, | ||
{ | ||
code: 'ja', | ||
iso: 'ja-JP', | ||
name: 'Japanese' | ||
} | ||
] | ||
}) | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// https://nuxt.com/docs/guide/directory-structure/nuxt.config | ||
export default defineNuxtConfig({ | ||
modules: ['./modules/ExtendI18n'], | ||
|
||
extends: './layers/i18n-layer', | ||
|
||
vite: { | ||
build: { | ||
minify: false | ||
} | ||
}, | ||
|
||
experimental: { | ||
reactivityTransform: true | ||
}, | ||
|
||
i18n: { | ||
baseUrl: 'http://localhost:3000', | ||
locales: [ | ||
{ | ||
code: 'en', | ||
iso: 'en', | ||
name: 'English' | ||
}, | ||
{ | ||
code: 'fr', | ||
iso: 'fr-FR', | ||
name: 'Français' | ||
} | ||
], | ||
defaultLocale: 'en', | ||
skipSettingLocaleOnNavigate: true, | ||
detectBrowserLanguage: false | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "nuxt3-test-locale-codes", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"build": "nuxi build", | ||
"dev": "nuxi dev", | ||
"generate": "nuxi generate", | ||
"preview": "nuxi preview" | ||
}, | ||
"devDependencies": { | ||
"@nuxtjs/i18n": "latest", | ||
"nuxt": "latest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters