nuxt-i18n
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -5,2 +5,13 @@ # Change Log | ||
<a name="2.1.0"></a> | ||
# [2.1.0](https://github.com/paulgv/nuxt-i18n/compare/v2.0.1...v2.1.0) (2018-01-27) | ||
### Features | ||
* Add noPrefixDefaultLocale option ([dac14ae](https://github.com/paulgv/nuxt-i18n/commit/dac14ae)) | ||
* Add redirectRootToLocale option ([65cacfd](https://github.com/paulgv/nuxt-i18n/commit/65cacfd)) | ||
<a name="2.0.1"></a> | ||
@@ -12,3 +23,3 @@ ## [2.0.1](https://github.com/paulgv/nuxt-i18n/compare/v2.0.0...v2.0.1) (2018-01-27) | ||
<a name="2.0.0"></a> | ||
# [2.0.0](https://github.com/paulgv/nuxt-i18n/compare/v1.0.2...v2.0.0) (2018-01-26) | ||
# [2.0.0](https://github.com/paulgv/nuxt-i18n/compare/v1.1.0...v2.0.0) (2018-01-26) | ||
@@ -15,0 +26,0 @@ |
@@ -7,3 +7,5 @@ const { resolve } = require('path') | ||
module.exports = function (moduleOptions) { | ||
const defaults = {} | ||
const defaults = { | ||
noPrefixDefaultLocale: true | ||
} | ||
const options = merge(defaults, moduleOptions, this.options.i18n) | ||
@@ -17,2 +19,4 @@ | ||
routesOptions: options.routes, | ||
noPrefixDefaultLocale: options.noPrefixDefaultLocale, | ||
redirectRootToLocale: options.redirectRootToLocale, | ||
ignorePaths: options.ignorePaths | ||
@@ -19,0 +23,0 @@ }) |
@@ -16,2 +16,3 @@ const { has } = require('lodash') | ||
routesOptions, | ||
noPrefixDefaultLocale = true, | ||
ignorePaths = [], | ||
@@ -55,3 +56,3 @@ isChild = false }) => { | ||
// Don't change path when current route is a child | ||
if (code !== defaultLocale && !isChild) { | ||
if (!isChild) { | ||
// Add leading / if needed | ||
@@ -61,4 +62,6 @@ if (path.match(/^\//) === null) { | ||
} | ||
// Prefix path with locale code if not default locale | ||
path = `/${code}${path}` | ||
if (code !== defaultLocale || !noPrefixDefaultLocale) { | ||
// Prefix path with locale code if not default locale | ||
path = `/${code}${path}` | ||
} | ||
} | ||
@@ -65,0 +68,0 @@ const route = { path, component } |
import middleware from './middleware' | ||
middleware['i18n'] = function ({ app, route, error, hotReload }) { | ||
middleware['i18n'] = function ({ app, route, redirect, error, hotReload }) { | ||
const locales = <%= JSON.stringify(options.locales) %> | ||
const localeCodes = locales.map(l => l.code) | ||
const defaultLocale = '<%= options.defaultLocale %>' | ||
// Check if middleware called from hot-reloading, ignore | ||
if (hotReload) return | ||
// Handle / redirection | ||
if ( | ||
route.path === '/' && | ||
'<%= options.redirectRootToLocale %>' && | ||
!('<%= options.redirectRootToLocale %>' === '<%= options.defaultLocale %>' && <%= options.noPrefixDefaultLocale %> === true) && | ||
localeCodes.includes('<%= options.redirectRootToLocale %>')) { | ||
redirect('/<%= options.redirectRootToLocale %>/') | ||
} | ||
// Get locale from params | ||
@@ -9,0 +18,0 @@ let locale = defaultLocale |
{ | ||
"name": "nuxt-i18n", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "i18n for Nuxt", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -178,11 +178,12 @@ # nuxt-i18n | ||
| Option | Type | 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 | | ||
| Option | Type | Default | 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 | | ||
## Configuration example | ||
@@ -211,2 +212,4 @@ | ||
defaultLocale: 'en', | ||
noPrefixDefaultLocale: true, | ||
redirectRootToLocale: 'en', | ||
vueI18n: { | ||
@@ -213,0 +216,0 @@ messages: { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32412
219
253