nuxt-i18n
Advanced tools
Comparing version 6.20.4 to 6.20.5
{ | ||
"name": "nuxt-i18n", | ||
"version": "6.20.4", | ||
"version": "6.20.5", | ||
"description": "i18n for Nuxt", | ||
@@ -99,3 +99,4 @@ "license": "MIT", | ||
"@nuxt/types": "2.15.2", | ||
"@nuxtjs/eslint-config-typescript": "5.0.0", | ||
"@nuxtjs/composition-api": "0.21.0", | ||
"@nuxtjs/eslint-config-typescript": "6.0.0", | ||
"@nuxtjs/module-test-utils": "1.6.3", | ||
@@ -102,0 +103,0 @@ "@release-it/conventional-changelog": "2.0.1", |
@@ -24,2 +24,7 @@ import { resolve, join } from 'path' | ||
// Resolve langDir | ||
if (options.langDir) { | ||
options.langDir = this.nuxt.resolver.resolveAlias(options.langDir) | ||
} | ||
// Templates (including plugins). | ||
@@ -26,0 +31,0 @@ // This is done here rather than in the build hook to ensure the order the plugins are added |
@@ -22,1 +22,9 @@ <% | ||
%> | ||
<% if (options.langDir) { %> | ||
export const ASYNC_LOCALES = { | ||
<%= Array.from( | ||
new Set(options.locales.map(l => `'${l.file}': () => import('../${relativeToBuild(options.langDir, l.file)}' /* webpackChunkName: "lang-${l.file}" */)`)) | ||
).join(',\n ') %> | ||
} | ||
<% } %> |
@@ -165,3 +165,3 @@ import Vue from 'vue' | ||
if (redirectPath === route.fullPath) { | ||
if (!redirectPath || redirectPath === route.fullPath || redirectPath.startsWith('//')) { | ||
return '' | ||
@@ -279,3 +279,3 @@ } | ||
const extendVueI18nInstance = i18n => { | ||
i18n.locales = locales | ||
i18n.locales = klona(locales) | ||
i18n.localeProperties = klona(locales.find(l => l[LOCALE_CODE_KEY] === i18n.locale) || { code: i18n.locale }) | ||
@@ -282,0 +282,0 @@ i18n.defaultLocale = defaultLocale |
@@ -52,18 +52,29 @@ import './middleware' | ||
const localizedRoute = Object.assign({}, route) | ||
let localizedRoute = Object.assign({}, route) | ||
if (route.path && !route.name) { | ||
const isDefaultLocale = locale === defaultLocale | ||
// if route has a path defined but no name, resolve full route using the path | ||
const isPrefixed = | ||
// don't prefix default locale | ||
!(isDefaultLocale && [STRATEGIES.PREFIX_EXCEPT_DEFAULT, STRATEGIES.PREFIX_AND_DEFAULT].includes(strategy)) && | ||
// no prefix for any language | ||
!(strategy === STRATEGIES.NO_PREFIX) && | ||
// no prefix for different domains | ||
!i18n.differentDomains | ||
let path = (isPrefixed ? `/${locale}${route.path}` : route.path) | ||
path = path.replace(/\/+$/, '') + (trailingSlash ? '/' : '') || '/' | ||
localizedRoute.path = path | ||
const resolvedRoute = this.router.resolve(route.path).route | ||
const resolvedRouteName = this.getRouteBaseName(resolvedRoute) | ||
if (resolvedRouteName) { | ||
localizedRoute = { | ||
name: getLocaleRouteName(resolvedRouteName, locale), | ||
params: resolvedRoute.params, | ||
query: resolvedRoute.query, | ||
hash: resolvedRoute.hash | ||
} | ||
} else { | ||
const isDefaultLocale = locale === defaultLocale | ||
// if route has a path defined but no name, resolve full route using the path | ||
const isPrefixed = | ||
// don't prefix default locale | ||
!(isDefaultLocale && [STRATEGIES.PREFIX_EXCEPT_DEFAULT, STRATEGIES.PREFIX_AND_DEFAULT].includes(strategy)) && | ||
// no prefix for any language | ||
!(strategy === STRATEGIES.NO_PREFIX) && | ||
// no prefix for different domains | ||
!i18n.differentDomains | ||
if (isPrefixed) { | ||
localizedRoute.path = `/${locale}${route.path}` | ||
} | ||
localizedRoute.path = localizedRoute.path.replace(/\/+$/, '') + (trailingSlash ? '/' : '') || '/' | ||
} | ||
} else { | ||
@@ -82,3 +93,8 @@ if (!route.name && !route.path) { | ||
return this.router.resolve(localizedRoute).route | ||
const resolvedRoute = this.router.resolve(localizedRoute).route | ||
if (resolvedRoute.name) { | ||
return resolvedRoute | ||
} | ||
// If didn't resolve to an existing route then just return resolved route based on original input. | ||
return this.router.resolve(route).route | ||
} | ||
@@ -85,0 +101,0 @@ |
@@ -1,2 +0,7 @@ | ||
import { LOCALE_CODE_KEY, LOCALE_FILE_KEY, MODULE_NAME } from './options' | ||
import { | ||
LOCALE_CODE_KEY, | ||
LOCALE_FILE_KEY, | ||
MODULE_NAME/* <% if (options.langDir) { %> */, | ||
ASYNC_LOCALES/* <% } %> */ | ||
} from './options' | ||
@@ -20,3 +25,2 @@ /** | ||
if (file) { | ||
// Hiding template directives from eslint so that parsing doesn't break. | ||
/* <% if (options.langDir) { %> */ | ||
@@ -32,8 +36,3 @@ let messages | ||
try { | ||
const langFileModule = await import( | ||
/* webpackChunkName: "lang-[request]" */ | ||
/* webpackInclude: /\.(js|ts|json|ya?ml)$/ */ | ||
`~/<%= options.langDir %>${file}` | ||
) | ||
const getter = langFileModule.default || langFileModule | ||
const getter = await ASYNC_LOCALES[file]().then(m => m.default || m) | ||
messages = typeof getter === 'function' ? await Promise.resolve(getter(context, locale)) : getter | ||
@@ -40,0 +39,0 @@ } catch (error) { |
Sorry, the diff of this file is too big to display
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
137766
1664
31