forked from nuxt-modules/i18n
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- untracked book.json - untracked docs/basic-routing.md - untracked docs/basic-usage.md - untracked docs/chapter1.md - untracked docs/configuration-example.md - untracked docs/lang-switcher.md - untracked docs/lazy-load-translations.md - untracked docs/options.md - untracked docs/README.md - untracked docs/routing.md - untracked docs/routing/basic-routin.md - untracked docs/routing/customize-routes.md - untracked docs/routing/ignore-routes.md - untracked docs/seo.md - untracked docs/SUMMARY.md Auto commit by GitBook Editor
- Loading branch information
Showing
15 changed files
with
388 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"title": "nuxt-i18n", | ||
"gitbook": ">3.0.0", | ||
"root": "./docs", | ||
"plugins": [ | ||
"edit-link", | ||
"prism", | ||
"theme-vuejs-2", | ||
"-fontsettings", | ||
"github" | ||
], | ||
"pluginsConfig": { | ||
"edit-link": { | ||
"base": "https://github.com/nuxt-community/nuxt-i18n/tree/master/docs", | ||
"label": "Edit This Page" | ||
}, | ||
"github": { | ||
"url": "https://github.com/nuxt-community/nuxt-i18n" | ||
} | ||
}, | ||
"links": { | ||
"sharing": { | ||
"facebook": false, | ||
"twitter": 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,11 @@ | ||
# nuxt-i18n | ||
|
||
**nuxt-i18n** provides i18n features for your Nuxt project: | ||
|
||
* [vue-i18n](https://github.com/kazupon/vue-i18n) integration | ||
* Automatic routes generation prefixed with locales code | ||
* SEO tags generation | ||
* Translations messages lazy-loading | ||
|
||
|
||
|
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 @@ | ||
# Summary | ||
|
||
* [Introduction](README.md) | ||
* [Setup](chapter1.md) | ||
* [Basic Usage](basic-usage.md) | ||
* [Routing](routing.md) | ||
* [Basic Routing](routing/basic-routin.md) | ||
* [Customize Routes](routing/customize-routes.md) | ||
* [Ignore Routes](routing/ignore-routes.md) | ||
* [SEO](seo.md) | ||
* [Lang Switcher](lang-switcher.md) | ||
* [Lazy-load translations](lazy-load-translations.md) | ||
* [Options](options.md) | ||
* [Configuration Example](configuration-example.md) | ||
|
Empty file.
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,62 @@ | ||
# Basic Usage | ||
|
||
To quickly get started with **nuxt-i18n**, you can simply configure a list of languages supported in your project and setup translations through `vueI18n` option: | ||
|
||
```js | ||
{ | ||
modules: [ | ||
['nuxt-i18n', { | ||
locales: [ | ||
{ code: 'en' }, | ||
{ code: 'fr' }, | ||
{ code: 'es' } | ||
], | ||
defaultLocale: 'en', | ||
vueI18n: { | ||
fallbackLocale: 'en', | ||
messages: { | ||
en: { | ||
welcome: 'Welcome' | ||
}, | ||
fr: { | ||
welcome: 'Bienvenue' | ||
}, | ||
es: { | ||
welcome: 'Bienvenido' | ||
} | ||
} | ||
} | ||
}] | ||
] | ||
} | ||
``` | ||
|
||
With this setup, **nuxt-i18n** generates localized URLs for all your pages, using the locale code provided in the `locales` option as the prefix, except for the `defaultLocale`. | ||
|
||
The `vueI18n` is passed as is to **vue-i18n**, refer to the [doc](https://kazupon.github.io/vue-i18n/) for available options. | ||
|
||
## nuxt-link | ||
|
||
When rendering internal links in you app using `<nuxt-link>`, you need to get proper URLs for the current locale. To do this, **nuxt-i18n **registers a global mixin that provides some helper functions: | ||
|
||
* `localePath` – Returns the localized URL for a given page. The first parameter can be either the name of the route or an object for more complex routes. A locale code can be passed as the second parameter to generate a link for a specific language: | ||
|
||
```html | ||
<nuxt-link :to="localePath('index')">{{ $t('home') }}</nuxt-link> | ||
<nuxt-link :to="localePath('index', 'en')">Homepage in English</nuxt-link> | ||
<nuxt-link :to="localePath({ name: 'category-slug', params: { slug: category.slug } })"> | ||
{{ category.title }} | ||
</nuxt-link> | ||
``` | ||
|
||
Note that `localePath` uses the route's base name to generate the localized URL. The base name corresponds to the names Nuxt generates when parsing your `pages/` directory, more info in [Nuxt's doc](https://nuxtjs.org/guide/routing). | ||
|
||
* `switchLocalePath` – Returns a link to the current page in another language: | ||
|
||
```html | ||
<nuxt-link :to="switchLocalePath('en')">English</nuxt-link> | ||
<nuxt-link :to="switchLocalePath('fr')">Français</nuxt-link> | ||
``` | ||
|
||
|
||
|
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 @@ | ||
# Setup | ||
|
||
Add **nuxt-i18n** to your dependencies using Yarn: | ||
|
||
```Shell | ||
yarn add nuxt-i18n | ||
``` | ||
|
||
Or NPM: | ||
|
||
```Shell | ||
npm i nuxt-i18n | ||
``` | ||
|
||
Then add the module to `nuxt.config.js`: | ||
|
||
```js | ||
{ | ||
modules: [ | ||
['nuxt-i18n', { | ||
// Options | ||
}] | ||
] | ||
} | ||
``` | ||
|
||
|
||
|
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,58 @@ | ||
# Configuration Example | ||
|
||
```js | ||
{ | ||
modules: [ | ||
['nuxt-i18n', { | ||
locales: [ | ||
{ | ||
code: 'en', | ||
iso: 'en-US', | ||
name: 'English' | ||
}, | ||
{ | ||
code: 'fr', | ||
iso: 'fr-FR', | ||
name: 'Français' | ||
} | ||
], | ||
defaultLocale: 'en', | ||
noPrefixDefaultLocale: true, | ||
redirectRootToLocale: 'en', | ||
vueI18n: { | ||
messages: { | ||
fr: { | ||
home: 'Accueil', | ||
about: 'À propos', | ||
category: 'Catégorie' | ||
}, | ||
en: { | ||
home: 'Homepage', | ||
about: 'About us', | ||
category: 'Category' | ||
} | ||
}, | ||
fallbackLocale: 'en' | ||
}, | ||
routes: { | ||
about: { | ||
fr: '/a-propos', | ||
en: '/about-us' | ||
}, | ||
category: { | ||
fr: '/categorie' | ||
}, | ||
'category/_slug': { | ||
fr: '/categorie/:slug' | ||
} | ||
}, | ||
ignorePaths: [ | ||
'/fr/notlocalized' | ||
] | ||
}] | ||
] | ||
} | ||
``` | ||
|
||
|
||
|
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 @@ | ||
# Lang Switcher | ||
|
||
To display a lang switcher anywhere in your app, you can access options `locales` and `defaultLocale` which are both added to `app.$i18n`: | ||
|
||
```html | ||
<nuxt-link | ||
v-for="(locale, index) in $i18n.locales" | ||
v-if="locale.code !== $i18n.locale" | ||
:key="index" | ||
:exact="true" | ||
:to="switchLocalePath(locale.code)">{{ locale.name }}</nuxt-link> | ||
``` | ||
|
||
|
||
|
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,48 @@ | ||
# Lazy-load translations | ||
|
||
To prevent loading all translations at once, messages can be loaded asynchronously when a user loads the app or switches to another language. This can be done by setting option `loadLanguagesAsync` to `true` and by referencing your translations files in the `locales` option. Additionally, you might want to set the langDir option to match your files structure \(defaults to **lang/**\). | ||
|
||
Say your files are organized this way: | ||
|
||
``` | ||
nuxt/ | ||
├── lang/ | ||
│ ├── en-US.js | ||
│ ├── es-ES.js | ||
│ ├── fr-FR.js | ||
├── nuxt.config.js | ||
``` | ||
|
||
Your config could then reflect this files structure to let the module load messages from your translations files: | ||
|
||
```js | ||
{ | ||
['nuxt-i18n', { | ||
locales: [ | ||
{ | ||
code: 'en', | ||
iso: 'en-US', | ||
name: 'English', | ||
langFile: 'en-US.js' | ||
}, | ||
{ | ||
code: 'fr', | ||
iso: 'fr-FR', | ||
name: 'Français', | ||
langFile: 'fr-FR.js' | ||
}, | ||
{ | ||
code: 'es', | ||
iso: 'es-ES', | ||
name: 'Español', | ||
langFile: 'es-ES.js' | ||
} | ||
], | ||
loadLanguagesAsync: true, | ||
langDir: 'lang/' | ||
}], | ||
} | ||
``` | ||
|
||
|
||
|
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,17 @@ | ||
Options | ||
|
||
| Option | Type | Default value | Description | | ||
| :--- | :--- | :--- | :--- | | ||
| locales | Array | | A list of objects that describes the locales available in your app, each object should contain at least a \`code\` key | | ||
| defaultLocale | String | | The app's default locale, URLs for this language won't be prefixed with the locale code | | ||
| vueI18n | Object | | Configuration options for vue-i18n, refer to \[the doc\]\(http://kazupon.github.io/vue-i18n/en/api.html\#constructor-options\) for supported options | | ||
| routes | Object | | Custom routing configuration, if routes are omitted, Nuxt's default routes are used | | ||
| ignorePaths | Array | | A list of paths that should not be localized | | ||
| noPrefixDefaultLocale | Boolean | true | By default, paths generated for the default language don't contain a locale prefix, set this option to \`false\` to disable this behavior | | ||
| redirectRootToLocale | String | | Specify a locale to which the user should be redirected when visiting root URL \(/\), doesn't do anything if \`noPrefixDefaultLocale\` is enabled | | ||
| seo | Boolean | true | Set to \`false\` to disable SEO metadata generation | | ||
| loadLanguagesAsync | Boolean | false | If \`true\`, the module will attempt to asynchronously load translations from files defined in \`langFiles\`, when using this, \`vueI18n.messages\` can be omitted and language files should be referenced using a \`langFile\` key in \`locales\` objects | | ||
| langDir | String | lang/ | Directory in which translations files are stored \(used when loading translations asynchronously\) | | ||
|
||
|
||
|
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 @@ | ||
# | ||
|
||
|
||
|
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,38 @@ | ||
# Basic Routing | ||
|
||
**nuxt-i18n **overrides Nuxt default routes to add locale prefixes to every URL. | ||
Say your app supports two languages: French and English as the default language, and you have the following pages in your project: | ||
|
||
```asciidoc | ||
pages/ | ||
├── index.vue | ||
├── about.vue | ||
``` | ||
|
||
```js | ||
[ | ||
{ | ||
path: "/", | ||
component: _3237362a, | ||
name: "index-en" | ||
}, | ||
{ | ||
path: "/fr/", | ||
component: _3237362a, | ||
name: "index-fr" | ||
}, | ||
{ | ||
path: "/about", | ||
component: _71a6ebb4, | ||
name: "about-en" | ||
}, | ||
{ | ||
path: "/fr/about", | ||
component: _71a6ebb4, | ||
name: "about-fr" | ||
} | ||
] | ||
``` | ||
Note that routes for the English version do not have any prefix because it is the default language. If you want to have prefixes for all languages, either set `noPrefixDefaultLocale` option to `true`, or omit `defaultLocale` option. | ||
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 @@ | ||
# Customize Routes | ||
|
||
In some cases, you might want to translate URLs in addition to having them prefixed with the locale code, this can be achieved using the `routes` option: | ||
|
||
```js | ||
{ | ||
modules: [ | ||
['nuxt-i18n', { | ||
locales: [ | ||
{ code: 'en' }, | ||
{ code: 'fr' } | ||
], | ||
defaultLocale: 'en', | ||
routes: { | ||
about: { | ||
fr: '/a-propos', | ||
en: '/about-us' | ||
}, | ||
category: { | ||
fr: '/categorie' | ||
}, | ||
'category/_slug': { | ||
fr: '/categorie/:slug' | ||
} | ||
} | ||
}] | ||
] | ||
} | ||
``` | ||
|
||
|
||
|
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,24 @@ | ||
# Ignore Routes | ||
|
||
To prevent nuxt-i18n from generating localized URLs for some pages, use the `ignorePaths` option: | ||
|
||
```js | ||
{ | ||
modules: [ | ||
['nuxt-i18n', { | ||
ignorePaths: [ | ||
'/fr/notlocalized' | ||
] | ||
}] | ||
] | ||
} | ||
``` | ||
|
||
``` | ||
pages/ | ||
├── fr/ | ||
├──── notlocalized.vue <── this page will be skipped when generating localized routes | ||
``` | ||
|
||
|
||
|
Oops, something went wrong.