nuxt-i18n
Advanced tools
Comparing version 6.11.1 to 6.12.0
@@ -0,1 +1,16 @@ | ||
## [6.12.0](https://github.com/nuxt-community/nuxt-i18n/compare/v6.11.1...v6.12.0) (2020-05-25) | ||
### Features | ||
* add localeRoute API for getting the localized route ([#729](https://github.com/nuxt-community/nuxt-i18n/issues/729)) ([0c4bd52](https://github.com/nuxt-community/nuxt-i18n/commit/0c4bd52babdd868fdc254387589529600e1a3496)), closes [#728](https://github.com/nuxt-community/nuxt-i18n/issues/728) | ||
* add support for using localePath with no route name and path ([#727](https://github.com/nuxt-community/nuxt-i18n/issues/727)) ([7a011a0](https://github.com/nuxt-community/nuxt-i18n/commit/7a011a07bede6bad62f9faf44873643a1a8b0ec1)), closes [#691](https://github.com/nuxt-community/nuxt-i18n/issues/691) | ||
### Bug Fixes | ||
* don't do browser language detection during Nuxt generate ([#718](https://github.com/nuxt-community/nuxt-i18n/issues/718)) ([f1c5aca](https://github.com/nuxt-community/nuxt-i18n/commit/f1c5aca9aa35febdb19f46c45b0cf37ba5ab3db6)) | ||
* don't leave out non-prefixed routes for generate + prefix strategy ([#726](https://github.com/nuxt-community/nuxt-i18n/issues/726)) ([97fabbf](https://github.com/nuxt-community/nuxt-i18n/commit/97fabbfafa2c7ec852f134c6587b291e4f5dfda9)), closes [#700](https://github.com/nuxt-community/nuxt-i18n/issues/700) | ||
* trigger language detection on initial load in generated mode ([#724](https://github.com/nuxt-community/nuxt-i18n/issues/724)) ([a853de9](https://github.com/nuxt-community/nuxt-i18n/commit/a853de929d2f764ccd08c4323c6cfb8f95e4490c)) | ||
### [6.11.1](https://github.com/nuxt-community/nuxt-i18n/compare/v6.11.0...v6.11.1) (2020-05-10) | ||
@@ -2,0 +17,0 @@ |
{ | ||
"name": "nuxt-i18n", | ||
"version": "6.11.1", | ||
"version": "6.12.0", | ||
"description": "i18n for Nuxt", | ||
@@ -96,25 +96,27 @@ "license": "MIT", | ||
"@babel/runtime": "7.9.6", | ||
"@nuxt/types": "0.7.5", | ||
"@nuxtjs/eslint-config-typescript": "1.0.2", | ||
"@nuxt/types": "0.7.6", | ||
"@nuxtjs/eslint-config-typescript": "2.0.0", | ||
"@nuxtjs/module-test-utils": "1.6.1", | ||
"@release-it/conventional-changelog": "1.1.4", | ||
"@types/jest": "25.2.1", | ||
"@types/argparse": "1.0.38", | ||
"@types/jest": "25.2.3", | ||
"@types/jest-dev-server": "4.2.0", | ||
"argparse": "1.0.10", | ||
"babel-core": "7.0.0-bridge.0", | ||
"babel-eslint": "10.1.0", | ||
"chromedriver": "81.0.0", | ||
"codecov": "3.6.5", | ||
"codecov": "3.7.0", | ||
"core-js": "3.6.5", | ||
"eslint": "7.0.0", | ||
"geckodriver": "1.19.1", | ||
"eslint": "6.8.0", | ||
"finalhandler": "1.1.2", | ||
"jest": "26.0.1", | ||
"jest-dev-server": "4.4.0", | ||
"jsdom": "16.2.2", | ||
"messageformat": "2.3.0", | ||
"nuxt": "2.12.2", | ||
"puppeteer-core": "3.0.4", | ||
"release-it": "13.5.8", | ||
"selenium-webdriver": "4.0.0-alpha.7", | ||
"tib": "0.7.4", | ||
"typescript": "3.8.3", | ||
"vuepress": "1.4.1" | ||
"playwright-chromium": "1.0.2", | ||
"release-it": "13.6.1", | ||
"serve-static": "1.14.1", | ||
"typescript": "3.9.3", | ||
"vuepress": "1.5.0" | ||
} | ||
} |
@@ -10,2 +10,3 @@ const { STRATEGIES } = require('./constants') | ||
defaultLocaleRouteNameSuffix, | ||
isNuxtGenerate, | ||
strategy, | ||
@@ -122,2 +123,9 @@ parsePages, | ||
path = `/${locale}${path}` | ||
if (locale === defaultLocale && strategy === STRATEGIES.PREFIX && isNuxtGenerate) { | ||
routes.push({ | ||
path: route.path, | ||
redirect: path | ||
}) | ||
} | ||
} | ||
@@ -124,0 +132,0 @@ |
@@ -42,2 +42,3 @@ const { resolve, join } = require('path') | ||
...options, | ||
IS_UNIVERSAL_MODE: this.options.mode === 'universal', | ||
MODULE_NAME, | ||
@@ -58,3 +59,4 @@ LOCALE_CODE_KEY, | ||
if (localeCodes.length) { | ||
this.extendRoutes((routes) => { | ||
let isNuxtGenerate = false | ||
const extendRoutes = routes => { | ||
// This import (or more specifically 'vue-template-compiler' in helpers/components.js) needs to | ||
@@ -67,7 +69,13 @@ // be required only at build time to avoid problems when 'vue-template-compiler' dependency is | ||
...options, | ||
pagesDir | ||
pagesDir, | ||
isNuxtGenerate | ||
}) | ||
routes.splice(0, routes.length) | ||
routes.unshift(...localizedRoutes) | ||
}) | ||
} | ||
// Doesn't seem like we can tell whether we are in nuxt generate from the module so we'll | ||
// take advantage of the 'generate:before' hook to store variable. | ||
this.nuxt.hook('generate:before', () => { isNuxtGenerate = true }) | ||
this.nuxt.hook('build:extendRoutes', routes => extendRoutes(routes, isNuxtGenerate)) | ||
} | ||
@@ -74,0 +82,0 @@ } else if (options.differentDomains) { |
@@ -11,2 +11,3 @@ import Vue from 'vue' | ||
differentDomains, | ||
IS_UNIVERSAL_MODE, | ||
lazy, | ||
@@ -130,2 +131,7 @@ LOCALE_CODE_KEY, | ||
const doDetectBrowserLanguage = () => { | ||
// Browser detection is ignored if it is a nuxt generate. | ||
if (process.static && process.server) { | ||
return false | ||
} | ||
const { alwaysRedirect, fallbackLocale } = detectBrowserLanguage | ||
@@ -241,2 +247,7 @@ | ||
await loadAndSetLocale(finalLocale, { initialSetup: true }) | ||
// Trigger onNavigate manually for Nuxt generate in universal mode as Nuxt doesn't do that on load. | ||
if (process.client && process.static && IS_UNIVERSAL_MODE) { | ||
await onNavigate() | ||
} | ||
} |
@@ -16,2 +16,12 @@ import './middleware' | ||
function localePath (route, locale) { | ||
const localizedRoute = localeRoute.call(this, route, locale) | ||
if (!localizedRoute) { | ||
return | ||
} | ||
return localizedRoute.fullPath | ||
} | ||
function localeRoute (route, locale) { | ||
// Abort if no route or no locale | ||
@@ -63,12 +73,7 @@ if (!route) { | ||
} else { | ||
// otherwise resolve route via the route name | ||
// Build localized route options | ||
let name = route.name + (strategy === STRATEGIES.NO_PREFIX ? '' : routesNameSeparator + locale) | ||
// Match route without prefix for default locale | ||
if (locale === defaultLocale && strategy === STRATEGIES.PREFIX_AND_DEFAULT) { | ||
name += routesNameSeparator + defaultLocaleRouteNameSuffix | ||
if (!route.name && !route.path) { | ||
localizedRoute.name = this.getRouteBaseName() | ||
} | ||
localizedRoute.name = name | ||
localizedRoute.name = getLocaleRouteName(localizedRoute.name, locale) | ||
@@ -81,5 +86,3 @@ const { params } = localizedRoute | ||
// Resolve localized route | ||
const { route: { fullPath } } = this.router.resolve(localizedRoute) | ||
return fullPath | ||
return this.router.resolve(localizedRoute).route | ||
} | ||
@@ -144,2 +147,13 @@ | ||
function getLocaleRouteName (routeName, locale) { | ||
const 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 | ||
} | ||
return name | ||
} | ||
const VueInstanceProxy = function (targetFunction) { | ||
@@ -184,2 +198,3 @@ return function () { | ||
localePath: VueInstanceProxy(localePath), | ||
localeRoute: VueInstanceProxy(localeRoute), | ||
switchLocalePath: VueInstanceProxy(switchLocalePath), | ||
@@ -196,4 +211,5 @@ getRouteBaseName: VueInstanceProxy(getRouteBaseName) | ||
app.localePath = NuxtContextProxy(context, localePath) | ||
app.localeRoute = NuxtContextProxy(context, localeRoute) | ||
app.switchLocalePath = NuxtContextProxy(context, switchLocalePath) | ||
app.getRouteBaseName = NuxtContextProxy(context, getRouteBaseName) | ||
} |
@@ -25,2 +25,3 @@ import Vue from 'vue' | ||
localePath(route: RawLocation, locale?: string): string | ||
localeRoute(route: RawLocation, locale?: string): Route | undefined | ||
switchLocalePath(locale: string): string | ||
@@ -27,0 +28,0 @@ getRouteBaseName(route?: Route): string |
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
97159
1381
27