nuxt-i18n
Advanced tools
Comparing version 6.22.2 to 6.22.3
{ | ||
"name": "nuxt-i18n", | ||
"version": "6.22.2", | ||
"version": "6.22.3", | ||
"description": "i18n for Nuxt", | ||
@@ -95,2 +95,3 @@ "license": "MIT", | ||
"cookie": "^0.4.0", | ||
"devalue": "^2.0.1", | ||
"is-https": "^3.0.0", | ||
@@ -104,7 +105,7 @@ "js-cookie": "^2.2.1", | ||
"devDependencies": { | ||
"@babel/core": "7.13.8", | ||
"@babel/preset-env": "7.13.8", | ||
"@babel/runtime": "7.13.8", | ||
"@babel/core": "7.13.13", | ||
"@babel/preset-env": "7.13.12", | ||
"@babel/runtime": "7.13.10", | ||
"@nuxt/types": "2.15.3", | ||
"@nuxtjs/composition-api": "0.21.0", | ||
"@nuxtjs/composition-api": "0.22.4", | ||
"@nuxtjs/eslint-config-typescript": "6.0.0", | ||
@@ -116,6 +117,6 @@ "@nuxtjs/module-test-utils": "1.6.3", | ||
"@types/express": "4.17.11", | ||
"@types/jest": "26.0.20", | ||
"@types/jest": "26.0.22", | ||
"@types/jest-dev-server": "4.2.0", | ||
"@types/js-cookie": "2.2.6", | ||
"@types/jsdom": "16.2.6", | ||
"@types/jsdom": "16.2.9", | ||
"@types/lodash.merge": "4.6.6", | ||
@@ -129,3 +130,3 @@ "@types/request-promise-native": "1.0.17", | ||
"core-js": "3.9.1", | ||
"eslint": "7.21.0", | ||
"eslint": "7.23.0", | ||
"express": "4.17.1", | ||
@@ -135,10 +136,10 @@ "husky": "4.3.8", | ||
"jest-dev-server": "4.4.0", | ||
"jsdom": "16.4.0", | ||
"jsdom": "16.5.1", | ||
"messageformat": "2.3.0", | ||
"nuxt": "2.15.2", | ||
"playwright-chromium": "1.9.1", | ||
"release-it": "14.4.1", | ||
"nuxt": "2.15.3", | ||
"playwright-chromium": "1.10.0", | ||
"release-it": "14.5.0", | ||
"serve-static": "1.14.1", | ||
"typescript": "4.2.2" | ||
"typescript": "4.2.3" | ||
} | ||
} |
@@ -16,5 +16,5 @@ import Vue from 'vue' | ||
export const asyncLocales: Record<string, () => Promise<LocaleFileExport>> | ||
export const localeMessages: Record<string, () => Promise<LocaleFileExport>> | ||
export const Constants: ModuleConstants | ||
export const nuxtOptions: ModuleNuxtOptions | ||
export const options: ResolvedOptions |
<% | ||
const { lazy, locales, langDir, vueI18n } = options.options | ||
const { fallbackLocale } = vueI18n || {} | ||
let fallbackLocaleFile = '' | ||
if (lazy && langDir && vueI18n && fallbackLocale && typeof (fallbackLocale) === 'string') { | ||
const l = locales.find(l => l.code === fallbackLocale) | ||
if (l) { | ||
fallbackLocaleFile = l.file | ||
%>import fallbackMessages from '<%= `../${relativeToBuild(langDir, l.file)}` %>' | ||
<% | ||
} | ||
} | ||
function stringifyValue(value) { | ||
@@ -31,8 +44,16 @@ if (value === undefined || typeof value === 'function') { | ||
const { lazy, locales, langDir } = options.options | ||
if (lazy && langDir) { %> | ||
export const asyncLocales = { | ||
<%= Array.from( | ||
new Set(locales.map(l => `'${l.file}': () => import('../${relativeToBuild(langDir, l.file)}' /* webpackChunkName: "lang-${l.file}" */)`)) | ||
).join(',\n ') %> | ||
export const localeMessages = { | ||
<% | ||
const files = new Set(locales.map(l => l.file)) | ||
// The messages for the fallback locale are imported synchronously and available from the main bundle as then | ||
// it doesn't need to be included in every server-side response and can take better advantage of browser caching. | ||
for (const file of files) { | ||
if (file === fallbackLocaleFile) {%> | ||
<%= `'${file}': () => Promise.resolve(fallbackMessages),` %><% | ||
} else {%> | ||
<%= `'${file}': () => import('../${relativeToBuild(langDir, file)}' /* webpackChunkName: "lang-${file}" */),` %><% | ||
} | ||
} | ||
%> | ||
} | ||
@@ -39,0 +60,0 @@ <% |
@@ -40,2 +40,3 @@ import Vue from 'vue' | ||
if (process.server && options.lazy) { | ||
const devalue = (await import('devalue')).default | ||
context.beforeNuxtRender(({ nuxtState }) => { | ||
@@ -45,8 +46,14 @@ /** @type {Record<string, import('vue-i18n').LocaleMessageObject>} */ | ||
const { fallbackLocale, locale } = app.i18n | ||
if (locale) { | ||
langs[locale] = app.i18n.getLocaleMessage(locale) | ||
if (locale && locale !== fallbackLocale) { | ||
// @ts-ignore Using internal API to avoid unnecessary cloning. | ||
const messages = app.i18n._getMessages()[locale] | ||
if (messages) { | ||
try { | ||
devalue(messages) | ||
langs[locale] = messages | ||
} catch { | ||
// Ignore - client-side will load the chunk asynchronously. | ||
} | ||
} | ||
} | ||
if (typeof (fallbackLocale) === 'string' && locale !== fallbackLocale) { | ||
langs[fallbackLocale] = app.i18n.getLocaleMessage(fallbackLocale) | ||
} | ||
nuxtState.__i18n = { langs } | ||
@@ -87,3 +94,2 @@ }) | ||
// Lazy-loading enabled | ||
if (options.lazy) { | ||
@@ -90,0 +96,0 @@ const i18nFallbackLocale = app.i18n.fallbackLocale |
@@ -1,2 +0,2 @@ | ||
import { asyncLocales } from './options' | ||
import { localeMessages } from './options' | ||
import { formatMessage } from './utils-common' | ||
@@ -33,3 +33,3 @@ | ||
if (context.isDev) { | ||
asyncLocales[file]() | ||
localeMessages[file]() | ||
} | ||
@@ -41,3 +41,3 @@ } | ||
// @ts-ignore | ||
const getter = await asyncLocales[file]().then(m => m.default || m) | ||
const getter = await localeMessages[file]().then(m => m.default || m) | ||
messages = typeof getter === 'function' ? await Promise.resolve(getter(context, locale)) : getter | ||
@@ -44,0 +44,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
153842
2006
12
+ Addeddevalue@^2.0.1
+ Addeddevalue@2.0.1(transitive)