-
-
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 basic module locale merging (#1955)
* feat: add basic module locale merging * refactor: rewrite LocaleObject merging to be generic and reusable * fix: register module hook type * docs: add documentation describing registerModule hook * test: add register module hook test
- Loading branch information
1 parent
c1d4ec9
commit d898a07
Showing
21 changed files
with
439 additions
and
81 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { createResolver, defineNuxtModule } from '@nuxt/kit' | ||
|
||
export default defineNuxtModule({ | ||
async setup(options, nuxt) { | ||
const { resolve } = createResolver(import.meta.url) | ||
nuxt.hook('i18n:registerModule', register => { | ||
register({ | ||
langDir: resolve('./locales'), | ||
locales: [ | ||
{ | ||
code: 'en', | ||
iso: 'en-US', | ||
file: 'en.json', | ||
name: 'English' | ||
}, | ||
{ | ||
code: 'fr', | ||
iso: 'fr-FR', | ||
file: 'fr.json', | ||
name: 'Francais' | ||
}, | ||
{ | ||
code: 'nl', | ||
iso: 'nl-NL', | ||
file: 'nl.json', | ||
name: 'Nederlands' | ||
} | ||
] | ||
}) | ||
}) | ||
} | ||
}) |
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,3 @@ | ||
{ | ||
"moduleLayerText": "This is a merged module layer locale key" | ||
} |
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,3 @@ | ||
{ | ||
"moduleLayerText": "This is a merged module layer locale key in French" | ||
} |
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,3 @@ | ||
{ | ||
"moduleLayerText": "This is a merged module layer locale key in Dutch" | ||
} |
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,34 @@ | ||
// import type { NuxtApp } from 'nuxt/dist/app/index' | ||
|
||
// https://nuxt.com/docs/guide/directory-structure/nuxt.config | ||
export default defineNuxtConfig({ | ||
modules: ['@nuxtjs/i18n'], | ||
i18n: { | ||
langDir: 'locales', | ||
lazy: true, | ||
baseUrl: 'http://localhost:3000', | ||
locales: [ | ||
{ | ||
code: 'en', | ||
iso: 'en-US', | ||
file: 'en.json', | ||
// domain: 'localhost', | ||
name: 'English' | ||
}, | ||
{ | ||
code: 'fr', | ||
iso: 'fr-FR', | ||
file: 'fr.json', | ||
// domain: 'localhost', | ||
name: 'Francais' | ||
}, | ||
{ | ||
code: 'nl', | ||
iso: 'nl-NL', | ||
file: 'nl.json', | ||
// domain: 'localhost', | ||
name: 'Nederlands' | ||
} | ||
] | ||
} | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { createResolver, defineNuxtModule } from '@nuxt/kit' | ||
|
||
export default defineNuxtModule({ | ||
async setup(options, nuxt) { | ||
const { resolve } = createResolver(import.meta.url) | ||
nuxt.hook('i18n:registerModule', register => { | ||
register({ | ||
langDir: resolve('./locales'), | ||
locales: [ | ||
{ | ||
code: 'en', | ||
iso: 'en-US', | ||
file: 'en.json', | ||
name: 'English' | ||
}, | ||
{ | ||
code: 'fr', | ||
iso: 'fr-FR', | ||
file: 'fr.json', | ||
name: 'Francais' | ||
}, | ||
{ | ||
code: 'nl', | ||
iso: 'nl-NL', | ||
file: 'nl.json', | ||
name: 'Nederlands' | ||
} | ||
] | ||
}) | ||
}) | ||
} | ||
}) |
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,3 @@ | ||
{ | ||
"moduleLayerText": "This is a merged module layer locale key" | ||
} |
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,3 @@ | ||
{ | ||
"moduleLayerText": "This is a merged module layer locale key in French" | ||
} |
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,3 @@ | ||
{ | ||
"moduleLayerText": "This is a merged module layer locale key in Dutch" | ||
} |
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,34 @@ | ||
// import type { NuxtApp } from 'nuxt/dist/app/index' | ||
|
||
// https://nuxt.com/docs/guide/directory-structure/nuxt.config | ||
export default defineNuxtConfig({ | ||
modules: ['@nuxtjs/i18n'], | ||
i18n: { | ||
langDir: 'locales', | ||
lazy: true, | ||
baseUrl: 'http://localhost:3000', | ||
locales: [ | ||
{ | ||
code: 'en', | ||
iso: 'en-US', | ||
file: 'en.json', | ||
// domain: 'localhost', | ||
name: 'English' | ||
}, | ||
{ | ||
code: 'fr', | ||
iso: 'fr-FR', | ||
file: 'fr.json', | ||
// domain: 'localhost', | ||
name: 'Francais' | ||
}, | ||
{ | ||
code: 'nl', | ||
iso: 'nl-NL', | ||
file: 'nl.json', | ||
// domain: 'localhost', | ||
name: 'Nederlands' | ||
} | ||
] | ||
} | ||
}) |
Oops, something went wrong.