nuxt-i18n
Advanced tools
Comparing version 6.14.2 to 6.15.0
@@ -0,1 +1,13 @@ | ||
## [6.15.0](https://github.com/nuxt-community/i18n-module/compare/v6.14.2...v6.15.0) (2020-09-10) | ||
### Features | ||
* add option to only detect browser locale on root path ([#799](https://github.com/nuxt-community/i18n-module/issues/799)) ([7bdb227](https://github.com/nuxt-community/i18n-module/commit/7bdb227dfb6c2c4ee1474f09add28dd8afc99764)), closes [#455](https://github.com/nuxt-community/i18n-module/issues/455) [#761](https://github.com/nuxt-community/i18n-module/issues/761) | ||
### Bug Fixes | ||
* **differentDomains:** Match domain properly on client if port provided ([#832](https://github.com/nuxt-community/i18n-module/issues/832)) ([3a0bc88](https://github.com/nuxt-community/i18n-module/commit/3a0bc88e6acb5c08d1d0f5567bc9f9ce12db56d4)) | ||
### [6.14.2](https://github.com/nuxt-community/i18n-module/compare/v6.14.1...v6.14.2) (2020-09-08) | ||
@@ -2,0 +14,0 @@ |
{ | ||
"name": "nuxt-i18n", | ||
"version": "6.14.2", | ||
"version": "6.15.0", | ||
"description": "i18n for Nuxt", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -40,3 +40,4 @@ const packageJson = require('../../package.json') | ||
alwaysRedirect: false, | ||
fallbackLocale: '' | ||
fallbackLocale: '', | ||
onlyOnRoot: false | ||
}, | ||
@@ -43,0 +44,0 @@ differentDomains: false, |
@@ -41,2 +41,3 @@ import deepcopy from 'deepcopy' | ||
const { alwaysRedirect, onlyOnRoot, fallbackLocale } = detectBrowserLanguage | ||
const getLocaleFromRoute = createLocaleFromRouteGetter(localeCodes, { routesNameSeparator, defaultLocaleRouteNameSuffix }) | ||
@@ -83,6 +84,6 @@ | ||
app.i18n.beforeLanguageSwitch(oldLocale, newLocale) | ||
} | ||
if (useCookie) { | ||
app.i18n.setLocaleCookie(newLocale) | ||
} | ||
if (useCookie) { | ||
app.i18n.setLocaleCookie(newLocale) | ||
} | ||
@@ -129,3 +130,7 @@ | ||
if (getLocaleFromRoute(route) === locale) { | ||
return '' | ||
// If "onlyOnRoot" is set and strategy is "prefix_and_default", prefer unprefixed route for | ||
// default locale. | ||
if (!onlyOnRoot || locale !== defaultLocale || strategy !== STRATEGIES.PREFIX_AND_DEFAULT) { | ||
return '' | ||
} | ||
} | ||
@@ -172,3 +177,3 @@ | ||
const finalLocale = | ||
(detectBrowserLanguage && doDetectBrowserLanguage()) || | ||
(detectBrowserLanguage && doDetectBrowserLanguage(route)) || | ||
getLocaleFromRoute(route) || app.i18n.locale || app.i18n.defaultLocale || '' | ||
@@ -181,3 +186,3 @@ | ||
const doDetectBrowserLanguage = () => { | ||
const doDetectBrowserLanguage = route => { | ||
// Browser detection is ignored if it is a nuxt generate. | ||
@@ -188,3 +193,5 @@ if (process.static && process.server) { | ||
const { alwaysRedirect, fallbackLocale } = detectBrowserLanguage | ||
if (onlyOnRoot && strategy !== STRATEGIES.NO_PREFIX && route.path !== '/') { | ||
return false | ||
} | ||
@@ -208,4 +215,2 @@ let matchedLocale | ||
return finalLocale | ||
} else if (useCookie && !app.i18n.getLocaleCookie()) { | ||
app.i18n.setLocaleCookie(finalLocale) | ||
} | ||
@@ -254,3 +259,3 @@ } | ||
let finalLocale = detectBrowserLanguage && doDetectBrowserLanguage() | ||
let finalLocale = detectBrowserLanguage && doDetectBrowserLanguage(route) | ||
@@ -257,0 +262,0 @@ if (!finalLocale) { |
@@ -151,7 +151,6 @@ import './middleware' | ||
function getLocaleRouteName (routeName, locale) { | ||
const name = routeName + (strategy === STRATEGIES.NO_PREFIX ? '' : routesNameSeparator + locale) | ||
let name = routeName + (strategy === STRATEGIES.NO_PREFIX ? '' : routesNameSeparator + locale) | ||
// Match route without prefix for default locale | ||
if (locale === defaultLocale && strategy === STRATEGIES.PREFIX_AND_DEFAULT) { | ||
return name + routesNameSeparator + defaultLocaleRouteNameSuffix | ||
name += routesNameSeparator + defaultLocaleRouteNameSuffix | ||
} | ||
@@ -158,0 +157,0 @@ |
@@ -88,14 +88,14 @@ import Cookie from 'cookie' | ||
export const getLocaleDomain = (locales, req, { localDomainKey, localeCodeKey }) => { | ||
let hostname = null | ||
let host = null | ||
if (process.client) { | ||
hostname = window.location.hostname | ||
host = window.location.host | ||
} else if (req) { | ||
hostname = req.headers['x-forwarded-host'] || req.headers.host | ||
host = req.headers['x-forwarded-host'] || req.headers.host | ||
} | ||
if (hostname) { | ||
const localeDomain = locales.find(l => l[localDomainKey] === hostname) | ||
if (localeDomain) { | ||
return localeDomain[localeCodeKey] | ||
if (host) { | ||
const matchingLocale = locales.find(l => l[localDomainKey] === host) | ||
if (matchingLocale) { | ||
return matchingLocale[localeCodeKey] | ||
} | ||
@@ -102,0 +102,0 @@ } |
@@ -37,2 +37,3 @@ import VueI18n from 'vue-i18n' | ||
fallbackLocale?: Locale | null | ||
onlyOnRoot?: boolean | ||
} | ||
@@ -39,0 +40,0 @@ |
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
119264
1466