Skip to content

Commit

Permalink
fix: Resolve incomplete vue-i18n configuration and js/ts extensions r…
Browse files Browse the repository at this point in the history
…esources (#2025)

* fix: Resolve incomplete vue-i18n configuration and js/ts extensions resources

* fix: unit testing

* breaking: drop context passing

* fix: fork from `@nuxt/test-utils`

* fix: ignore lint errors for utils

* fix: update snapshot

* fix: update e2e

* fix: wrong path for pre-rendered

* fix: add spec fixtures

* fix

* refactor

* fix: update lock file
  • Loading branch information
kazupon authored May 8, 2023
1 parent c4e32e9 commit a069f38
Show file tree
Hide file tree
Showing 585 changed files with 12,941 additions and 1,912 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
dist
playground
specs/fixtures
specs/utils
test/fixtures
coverage
docs/components/content/Logo.vue
docs/components/content/VoltaBoard.vue
.eslintcache
.eslintcache
2 changes: 1 addition & 1 deletion docs/content/1.getting-started/2.basic-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default defineNuxtConfig({
```

```ts {}[i18n.config.ts]
export default defineI18nConfig(nuxt => ({
export default defineI18nConfig(() => ({
legacy: false,
locale: 'en',
messages: {
Expand Down
1 change: 1 addition & 0 deletions docs/content/2.guide/13.extend-messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Example:
export default defineNuxtModule({
async setup(options, nuxt) {
const { resolve } = createResolver(import.meta.url)
nuxt.hook('i18n:registerModule', register => {
register({
// langDir path needs to be resolved
Expand Down
1 change: 1 addition & 0 deletions docs/content/2.guide/14.extend-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Adding localized pages from a module.
::alert{type="info"}
This is a workaround, support for extending pages with localization regardless of module registration order may be added in the future.
::

::alert{type="warning"}
Your module has to registered before `@nuxtjs/i18n` to ensure localized routes are generated for the added pages.
::
Expand Down
2 changes: 1 addition & 1 deletion docs/content/3.options/1.vue-i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import en from '../locales/en.json'
import fr from '../locales/fr.yaml'

// You can use `defineI18nConfig` to get type inferences for options to pass to vue-i18n.
export default defineI18nConfig(nuxt => {
export default defineI18nConfig(() => {
return {
legacy: false,
locale: 'en',
Expand Down
22 changes: 5 additions & 17 deletions docs/content/4.API/1.composables.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,12 @@ You need return vue-i18n options object that will be resolved by Promise.
### Type

```ts
export function defineI18nConfig<Config extends I18nOptions>(loader: (context: NuxtApp) => Config | Promise<Config>): (context: NuxtApp) => Config | Promise<Config>;
export function defineI18nConfig<Config extends I18nOptions>(loader: () => Config | Promise<Config>): () => Config | Promise<Config>;
```

for example, define simple vue-i18n options object:
```ts
export default defineI18nConfig(nuxt => ({
export default defineI18nConfig(() => ({
legacy: false,
locale: 'en',
messages: {
Expand All @@ -213,13 +213,7 @@ export default defineI18nConfig(nuxt => ({

#### `loader`

A function that is the vue-i18n optionss loading, that has the following parameters:

- `context`

**Type**: `NuxtApp`

A Nuxt Application instance that is passed from nuxt i18n module.
A function that is the vue-i18n optionss loading.


## `defineI18nLocale`
Expand All @@ -235,12 +229,12 @@ You need return locale messags object that will be resolved by Promise.
### Type

```ts
declare function defineI18nLocale<Messages = LocaleMessages<DefineLocaleMessage>, Locales = Locale>(loader: (context: NuxtApp, locale: Locales) => Messages | Promise<Messages>): (context: NuxtApp, locale: Locales) => Messages | Promise<Messages>;
declare function defineI18nLocale<Messages = LocaleMessages<DefineLocaleMessage>, Locales = Locale>(loader: (locale: Locales) => Messages | Promise<Messages>): (locale: Locales) => Messages | Promise<Messages>;
```

for example, locale loading with fetch:
```ts
export default defineI18nLocale((context, locale) => {
export default defineI18nLocale(locale => {
return $fetch(`https://your-company-product/api/${locale}`)
})
```
Expand All @@ -251,12 +245,6 @@ export default defineI18nLocale((context, locale) => {

A function that is the dynamic locale messages loading, that has the following parameters:

- `context`

**Type**: `NuxtApp`

A Nuxt Application instance that is passed from nuxt i18n module.

- `locale`

**Type**: `Locale`
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"dev:build": "nuxi build playground",
"dev:generate": "nuxi generate playground",
"dev:preview": "nuxi preview playground",
"dev:clean": "rm -rf playground/.nuxt playground/dist playground/.output",
"docs:dev": "nuxi dev docs",
"docs:build": "nuxi build docs",
"docs:generate": "nuxi generate docs",
Expand Down Expand Up @@ -92,7 +93,7 @@
"pkg-types": "^1.0.2",
"ufo": "^1.1.0",
"unplugin": "^1.3.1",
"unstorage": "^1.4.1",
"unstorage": "^1.5.0",
"vue-i18n": "9.3.0-beta.17",
"vue-i18n-routing": "^0.13.0"
},
Expand All @@ -102,7 +103,6 @@
"@babel/types": "^7.21.4",
"@nuxt/module-builder": "latest",
"@nuxt/schema": "^3.4.1",
"@nuxt/test-utils": "^3.4.1",
"@types/debug": "^4.1.7",
"@types/js-cookie": "^3.0.3",
"@types/rimraf": "^3",
Expand All @@ -114,18 +114,21 @@
"eslint": "^8.38.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"execa": "^7.1.1",
"get-port-please": "^3.0.1",
"gh-changelogen": "^0.2.8",
"jiti": "^1.18.2",
"jsdom": "^21.1.1",
"lint-staged": "^13.2.1",
"npm-run-all": "^4.1.5",
"nuxt": "^3.4.1",
"ofetch": "^1.0.1",
"playwright": "^1.32.3",
"prettier": "^2.8.7",
"rimraf": "^4.4.1",
"ts-essentials": "^9.3.1",
"typescript": "^4.9.5",
"vitest": "^0.29.8",
"vitest": "^0.30.1",
"vue": "^3.2.47",
"yorkie": "^2.0.0"
},
Expand Down
3 changes: 2 additions & 1 deletion playground/locales/en-GB.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default defineI18nLocale(async function (context, locale) {
export default defineI18nLocale(async function (locale) {
console.log('Loading locale', locale)
return $fetch(`/api/${locale}`)
})
7 changes: 1 addition & 6 deletions playground/locales/ja.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
// import type { Locale } from 'vue-i18n'
// import type { NuxtApp } from '@nuxt/schema'

// export default function (context: NuxtApp, locale: Locale) {
export default async function (context, locale) {
console.log('dynamical resource loading ...', context, locale)
export default async function (locale) {
return {
layouts: {
title: 'ページ ー {title}'
Expand Down
2 changes: 1 addition & 1 deletion playground/locales/ja.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default async function (context, locale) {
export default async function (locale) {
return $fetch(`/api/${locale}`)
}
2 changes: 1 addition & 1 deletion playground/locales/ja.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default defineI18nLocale((context, locale) => {
export default defineI18nLocale(locale => {
return {
layouts: {
title: 'ページ ー {title}'
Expand Down
2 changes: 1 addition & 1 deletion playground/vue-i18n.options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fr from './locales/fr.json'

export default defineI18nConfig(nuxt => ({
export default defineI18nConfig(() => ({
legacy: false,
locale: 'en',
fallbackLocale: 'en',
Expand Down
Loading

0 comments on commit a069f38

Please sign in to comment.