nuxt-i18n
Advanced tools
Comparing version 6.13.0-beta.0 to 6.13.0
@@ -0,1 +1,16 @@ | ||
## [6.13.0](https://github.com/nuxt-community/nuxt-i18n/compare/v6.12.2...v6.13.0) (2020-07-02) | ||
### Features | ||
* pass to-be-loaded locale when lazy-loading from exported function ([#752](https://github.com/nuxt-community/nuxt-i18n/issues/752)) ([145f3b2](https://github.com/nuxt-community/nuxt-i18n/commit/145f3b2a080a91028fd5ef59f9c8bd88755d3b4b)), closes [#742](https://github.com/nuxt-community/nuxt-i18n/issues/742) | ||
### Bug Fixes | ||
* handling of trailing slash in localePath ([#756](https://github.com/nuxt-community/nuxt-i18n/issues/756)) ([1a69387](https://github.com/nuxt-community/nuxt-i18n/commit/1a6938784581789465b41035aadc181782c9d68e)), closes [#717](https://github.com/nuxt-community/nuxt-i18n/issues/717) | ||
* initial redirect breaks reactivity in static mode ([54b8186](https://github.com/nuxt-community/nuxt-i18n/commit/54b8186c711389ce051b8ffbd4f30e201332e5f8)), closes [#737](https://github.com/nuxt-community/nuxt-i18n/issues/737) | ||
* preserve query when handling rootRedirect ([#771](https://github.com/nuxt-community/nuxt-i18n/issues/771)) ([b201609](https://github.com/nuxt-community/nuxt-i18n/commit/b201609de36c11b7dd6c369bf08a7e43c9cc6b59)) | ||
* **types:** extend NuxtOptions with "i18n" (when using i18n in the root of Nuxt config) ([7c5241b](https://github.com/nuxt-community/nuxt-i18n/commit/7c5241bd17f6b5f8053b0c3b1e197be211677683)) | ||
## [6.13.0-beta.0](https://github.com/nuxt-community/nuxt-i18n/compare/v6.12.2...v6.13.0-beta.0) (2020-06-03) | ||
@@ -2,0 +17,0 @@ |
{ | ||
"name": "nuxt-i18n", | ||
"version": "6.13.0-beta.0", | ||
"version": "6.13.0", | ||
"description": "i18n for Nuxt", | ||
@@ -27,2 +27,3 @@ "license": "MIT", | ||
"dev:basic:generate": "nuxt generate -c ./test/fixture/basic/nuxt.config.js", | ||
"start:dist": "node -r esm ./test/utils/http-server-internal.js --port 8080 -v dist", | ||
"coverage": "codecov", | ||
@@ -94,12 +95,15 @@ "lint": "eslint --ext .js,.vue,.ts src test types", | ||
"devDependencies": { | ||
"@babel/core": "7.10.2", | ||
"@babel/preset-env": "7.10.2", | ||
"@babel/runtime": "7.10.2", | ||
"@nuxt/types": "0.7.7", | ||
"@babel/core": "7.10.4", | ||
"@babel/preset-env": "7.10.4", | ||
"@babel/runtime": "7.10.4", | ||
"@nuxt/types": "2.13.2", | ||
"@nuxtjs/eslint-config-typescript": "2.0.0", | ||
"@nuxtjs/module-test-utils": "1.6.1", | ||
"@nuxtjs/module-test-utils": "1.6.3", | ||
"@release-it/conventional-changelog": "1.1.4", | ||
"@types/argparse": "1.0.38", | ||
"@types/jest": "25.2.3", | ||
"@types/finalhandler": "1.1.0", | ||
"@types/jest": "26.0.3", | ||
"@types/jest-dev-server": "4.2.0", | ||
"@types/jsdom": "16.2.3", | ||
"@types/request-promise-native": "1.0.17", | ||
"argparse": "1.0.10", | ||
@@ -112,13 +116,13 @@ "babel-core": "7.0.0-bridge.0", | ||
"finalhandler": "1.1.2", | ||
"jest": "26.0.1", | ||
"jest": "26.1.0", | ||
"jest-dev-server": "4.4.0", | ||
"jsdom": "16.2.2", | ||
"messageformat": "2.3.0", | ||
"nuxt": "2.12.2", | ||
"playwright-chromium": "1.0.2", | ||
"release-it": "13.6.2", | ||
"nuxt": "2.13.2", | ||
"playwright-chromium": "1.1.1", | ||
"release-it": "13.6.4", | ||
"serve-static": "1.14.1", | ||
"typescript": "3.9.3", | ||
"vuepress": "1.5.0" | ||
"typescript": "3.9.6", | ||
"vuepress": "1.5.2" | ||
} | ||
} |
@@ -9,3 +9,9 @@ const { readFileSync } = require('fs') | ||
exports.extractComponentOptions = (path) => { | ||
/** | ||
* Extracts nuxtI18n component options for given component file path. | ||
* | ||
* @param {string} path The path to the component file | ||
* @return {Record<string, any>} | ||
*/ | ||
exports.extractComponentOptions = path => { | ||
let componentOptions = {} | ||
@@ -12,0 +18,0 @@ const Component = compiler.parseComponent(readFileSync(path).toString()) |
@@ -39,2 +39,3 @@ const { resolve, join } = require('path') | ||
const localeCodes = getLocaleCodes(options.locales) | ||
const { trailingSlash } = this.options.router | ||
@@ -51,6 +52,6 @@ const templatesOptions = { | ||
COMPONENT_OPTIONS_KEY, | ||
localeCodes | ||
localeCodes, | ||
trailingSlash | ||
} | ||
// Generate localized routes | ||
const pagesDir = this.options.dir && this.options.dir.pages ? this.options.dir.pages : 'pages' | ||
@@ -60,3 +61,2 @@ | ||
if (localeCodes.length) { | ||
const { trailingSlash } = this.options.router | ||
let isNuxtGenerate = false | ||
@@ -63,0 +63,0 @@ const extendRoutes = routes => { |
@@ -11,6 +11,7 @@ import middleware from '../middleware' | ||
const [status, redirectPath] = await app.i18n.__onNavigate(context.route) | ||
const [status, redirectPath, preserveQuery] = await app.i18n.__onNavigate(context.route) | ||
if (status && redirectPath) { | ||
context.redirect(status, redirectPath) | ||
const query = preserveQuery ? context.route.query : undefined | ||
context.redirect(status, redirectPath, query) | ||
} | ||
} |
@@ -129,2 +129,34 @@ import Vue from 'vue' | ||
// Called by middleware on navigation (also on the initial one). | ||
const onNavigate = async route => { | ||
// Handle root path redirect | ||
if (route.path === '/' && rootRedirect) { | ||
let statusCode = 302 | ||
let path = rootRedirect | ||
if (typeof rootRedirect !== 'string') { | ||
statusCode = rootRedirect.statusCode | ||
path = rootRedirect.path | ||
} | ||
return [statusCode, `/${path}`, /* preserve query */true] | ||
} | ||
const storedRedirect = app.i18n.__redirect | ||
if (storedRedirect) { | ||
app.i18n.__redirect = null | ||
return [302, storedRedirect] | ||
} | ||
app.i18n.__baseUrl = resolveBaseUrl(baseUrl, context) | ||
const finalLocale = | ||
(detectBrowserLanguage && doDetectBrowserLanguage()) || | ||
getLocaleFromRoute(route) || app.i18n.locale || app.i18n.defaultLocale || '' | ||
await app.i18n.setLocale(finalLocale) | ||
return [null, null] | ||
} | ||
const doDetectBrowserLanguage = () => { | ||
@@ -163,34 +195,2 @@ // Browser detection is ignored if it is a nuxt generate. | ||
// Called by middleware on navigation (also on the initial one). | ||
const onNavigate = async route => { | ||
// Handle root path redirect | ||
if (route.path === '/' && rootRedirect) { | ||
let statusCode = 302 | ||
let path = rootRedirect | ||
if (typeof rootRedirect !== 'string') { | ||
statusCode = rootRedirect.statusCode | ||
path = rootRedirect.path | ||
} | ||
return [statusCode, `/${path}`] | ||
} | ||
const storedRedirect = app.i18n.__redirect | ||
if (storedRedirect) { | ||
app.i18n.__redirect = null | ||
return [302, storedRedirect] | ||
} | ||
app.i18n.__baseUrl = resolveBaseUrl(baseUrl, context) | ||
const finalLocale = | ||
(detectBrowserLanguage && doDetectBrowserLanguage()) || | ||
getLocaleFromRoute(route) || app.i18n.locale || app.i18n.defaultLocale || '' | ||
await app.i18n.setLocale(finalLocale) | ||
return [null, null] | ||
} | ||
const extendVueI18nInstance = i18n => { | ||
@@ -232,23 +232,27 @@ i18n.locales = locales | ||
let finalLocale = app.i18n.defaultLocale || '' | ||
let finalLocale = detectBrowserLanguage && doDetectBrowserLanguage() | ||
if (vuex && vuex.syncLocale && store && store.state[vuex.moduleName].locale !== '') { | ||
finalLocale = store.state[vuex.moduleName].locale | ||
} else if (app.i18n.differentDomains) { | ||
const options = { localDomainKey: LOCALE_DOMAIN_KEY, localeCodeKey: LOCALE_CODE_KEY } | ||
const domainLocale = getLocaleDomain(locales, req, options) | ||
finalLocale = domainLocale || finalLocale | ||
} else if (strategy !== STRATEGIES.NO_PREFIX) { | ||
const routeLocale = getLocaleFromRoute(route) | ||
finalLocale = routeLocale || finalLocale | ||
} else if (useCookie) { | ||
finalLocale = app.i18n.getLocaleCookie() || finalLocale | ||
if (!finalLocale) { | ||
if (vuex && vuex.syncLocale && store && store.state[vuex.moduleName].locale !== '') { | ||
finalLocale = store.state[vuex.moduleName].locale | ||
} else if (app.i18n.differentDomains) { | ||
const options = { localDomainKey: LOCALE_DOMAIN_KEY, localeCodeKey: LOCALE_CODE_KEY } | ||
const domainLocale = getLocaleDomain(locales, req, options) | ||
finalLocale = domainLocale | ||
} else if (strategy !== STRATEGIES.NO_PREFIX) { | ||
const routeLocale = getLocaleFromRoute(route) | ||
finalLocale = routeLocale | ||
} else if (useCookie) { | ||
finalLocale = app.i18n.getLocaleCookie() | ||
} | ||
} | ||
const detectedBrowserLocale = detectBrowserLanguage && doDetectBrowserLanguage() | ||
finalLocale = detectedBrowserLocale || finalLocale | ||
if (!finalLocale) { | ||
finalLocale = app.i18n.defaultLocale || '' | ||
} | ||
await loadAndSetLocale(finalLocale, { initialSetup: true }) | ||
if (process.client && process.static && IS_UNIVERSAL_MODE) { | ||
const redirectTo = (await onNavigate(context.route))[1] | ||
const [_, redirectTo] = await onNavigate(context.route) | ||
if (redirectTo) { | ||
@@ -255,0 +259,0 @@ location.assign(redirectTo) |
@@ -12,2 +12,3 @@ import './middleware' | ||
strategy, | ||
trailingSlash, | ||
vuex | ||
@@ -69,4 +70,4 @@ } from './options' | ||
const path = (isPrefixed ? `/${locale}${route.path}` : route.path) | ||
let path = (isPrefixed ? `/${locale}${route.path}` : route.path) | ||
path = path.replace(/\/+$/, '') + (trailingSlash ? '/' : '') || '/' | ||
localizedRoute.path = path | ||
@@ -73,0 +74,0 @@ } else { |
@@ -10,2 +10,3 @@ import VueI18n from 'vue-i18n' | ||
type Locale = VueI18n.Locale | ||
type Strategies = 'no_prefix' | 'prefix_except_default' | 'prefix' | 'prefix_and_default' | ||
@@ -54,2 +55,3 @@ namespace Options { | ||
defaultLocale?: Locale | ||
defaultLocaleRouteNameSuffix?: string | ||
locales?: Array<Locale | LocaleObject> | ||
@@ -77,3 +79,3 @@ differentDomains?: boolean | ||
seo?: boolean | ||
strategy?: 'no_prefix' | 'prefix_except_default' | 'prefix' | 'prefix_and_default' | ||
strategy?: Strategies | ||
vueI18n?: VueI18n.I18nOptions | string | ||
@@ -80,0 +82,0 @@ vueI18nLoader?: boolean |
import Vue from 'vue' | ||
import { RawLocation, Route } from 'vue-router' | ||
import { Location, RawLocation, Route } from 'vue-router' | ||
import VueI18n, { IVueI18n } from 'vue-i18n' | ||
@@ -25,3 +25,3 @@ import { NuxtI18nComponentOptions, NuxtVueI18n, NuxtI18nSeo } from './nuxt-i18n' | ||
localePath(route: RawLocation, locale?: string): string | ||
localeRoute(route: RawLocation, locale?: string): Route | undefined | ||
localeRoute(route: RawLocation, locale?: string): Location | undefined | ||
switchLocalePath(locale: string): string | ||
@@ -48,2 +48,6 @@ getRouteBaseName(route?: Route): string | ||
} | ||
interface NuxtOptions { | ||
i18n?: NuxtVueI18n.Options.AllOptionsInterface | ||
} | ||
} | ||
@@ -50,0 +54,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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
108792
21
1413
1
30
2