nuxt-i18n
Advanced tools
Comparing version 6.18.0 to 6.19.0
@@ -0,1 +1,15 @@ | ||
## [6.19.0](https://github.com/nuxt-community/i18n-module/compare/v6.18.0...v6.19.0) (2021-02-01) | ||
### Features | ||
* add dir property and defaultDirection option ([#1023](https://github.com/nuxt-community/i18n-module/issues/1023)) ([3b3dcc6](https://github.com/nuxt-community/i18n-module/commit/3b3dcc6ba418ce6250498225873da3a063c8321c)) | ||
### Bug Fixes | ||
* invalid canonical SEO link with differentDomains ([#1049](https://github.com/nuxt-community/i18n-module/issues/1049)) ([d05317b](https://github.com/nuxt-community/i18n-module/commit/d05317be2eb26a211f1783c35a966b9d779feeb8)) | ||
* **deps:** update all non-major dependencies ([#1048](https://github.com/nuxt-community/i18n-module/issues/1048)) ([8f4cef5](https://github.com/nuxt-community/i18n-module/commit/8f4cef5d5335138e638e2c58b75ab77602f25c65)) | ||
* localeProperties undefined when <i18n> component used ([#1043](https://github.com/nuxt-community/i18n-module/issues/1043)) ([ff56a35](https://github.com/nuxt-community/i18n-module/commit/ff56a35a052487b17632e5ad6f08bf588f94f966)) | ||
## [6.18.0](https://github.com/nuxt-community/i18n-module/compare/v6.17.0...v6.18.0) (2021-01-13) | ||
@@ -2,0 +16,0 @@ |
{ | ||
"name": "nuxt-i18n", | ||
"version": "6.18.0", | ||
"version": "6.19.0", | ||
"description": "i18n for Nuxt", | ||
@@ -106,5 +106,5 @@ "license": "MIT", | ||
"@types/jest-dev-server": "4.2.0", | ||
"@types/jsdom": "16.2.5", | ||
"@types/jsdom": "16.2.6", | ||
"@types/request-promise-native": "1.0.17", | ||
"@types/serve-static": "1.13.8", | ||
"@types/serve-static": "1.13.9", | ||
"argparse": "2.0.1", | ||
@@ -114,4 +114,4 @@ "babel-core": "7.0.0-bridge.0", | ||
"codecov": "3.8.1", | ||
"core-js": "3.8.2", | ||
"eslint": "7.17.0", | ||
"core-js": "3.8.3", | ||
"eslint": "7.19.0", | ||
"finalhandler": "1.1.2", | ||
@@ -123,3 +123,3 @@ "jest": "26.6.3", | ||
"nuxt": "2.14.12", | ||
"playwright-chromium": "1.7.1", | ||
"playwright-chromium": "1.8.0", | ||
"release-it": "14.2.2", | ||
@@ -126,0 +126,0 @@ "serve-static": "1.14.1", |
@@ -8,2 +8,3 @@ const packageJson = require('../../package.json') | ||
exports.LOCALE_ISO_KEY = 'iso' | ||
exports.LOCALE_DIR_KEY = 'dir' | ||
exports.LOCALE_DOMAIN_KEY = 'domain' | ||
@@ -28,2 +29,3 @@ exports.LOCALE_FILE_KEY = 'file' | ||
defaultLocale: '', | ||
defaultDirection: 'ltr', | ||
routesNameSeparator: '___', | ||
@@ -30,0 +32,0 @@ defaultLocaleRouteNameSuffix: 'default', |
import { resolve, join } from 'path' | ||
import { readdirSync } from 'fs' | ||
import { directive as i18nExtensionsDirective } from '@intlify/vue-i18n-extensions' | ||
import { MODULE_NAME, COMPONENT_OPTIONS_KEY, DEFAULT_OPTIONS, LOCALE_CODE_KEY, LOCALE_ISO_KEY, LOCALE_DOMAIN_KEY, LOCALE_FILE_KEY, NESTED_OPTIONS, ROOT_DIR, STRATEGIES } from './helpers/constants' | ||
import { MODULE_NAME, COMPONENT_OPTIONS_KEY, DEFAULT_OPTIONS, LOCALE_CODE_KEY, LOCALE_ISO_KEY, LOCALE_DIR_KEY, LOCALE_DOMAIN_KEY, LOCALE_FILE_KEY, NESTED_OPTIONS, ROOT_DIR, STRATEGIES } from './helpers/constants' | ||
import { getLocaleCodes } from './helpers/utils' | ||
@@ -37,2 +37,3 @@ import { buildHook, createExtendRoutesHook } from './core/hooks' | ||
LOCALE_ISO_KEY, | ||
LOCALE_DIR_KEY, | ||
LOCALE_DOMAIN_KEY, | ||
@@ -39,0 +40,0 @@ LOCALE_FILE_KEY, |
import Vue from 'vue' | ||
import VueI18n from 'vue-i18n' | ||
import { nuxtI18nSeo } from './seo-head' | ||
import { nuxtI18nHead, nuxtI18nSeo } from './head-meta' | ||
import { | ||
@@ -192,3 +192,4 @@ baseUrl, | ||
app.i18n.__baseUrl = resolveBaseUrl(baseUrl, context) | ||
const options = { differentDomains, locales, localeDomainKey: LOCALE_DOMAIN_KEY, localeCodeKey: LOCALE_CODE_KEY, moduleName: MODULE_NAME } | ||
app.i18n.__baseUrl = resolveBaseUrl(baseUrl, context, app.i18n.locale, options) | ||
@@ -256,2 +257,3 @@ const finalLocale = | ||
i18n.locales = locales | ||
i18n.localeProperties = klona(locales.find(l => l[LOCALE_CODE_KEY] === i18n.locale) || { code: i18n.locale }) | ||
i18n.defaultLocale = defaultLocale | ||
@@ -277,7 +279,8 @@ i18n.differentDomains = differentDomains | ||
extendVueI18nInstance(app.i18n) | ||
app.i18n.__baseUrl = resolveBaseUrl(baseUrl, context) | ||
const options = { differentDomains, locales, localeDomainKey: LOCALE_DOMAIN_KEY, localeCodeKey: LOCALE_CODE_KEY, moduleName: MODULE_NAME } | ||
app.i18n.__baseUrl = resolveBaseUrl(baseUrl, context, '', options) | ||
app.i18n.__onNavigate = onNavigate | ||
// Inject seo function | ||
Vue.prototype.$nuxtI18nSeo = nuxtI18nSeo | ||
Vue.prototype.$nuxtI18nHead = nuxtI18nHead | ||
@@ -301,3 +304,3 @@ if (store) { | ||
} else if (app.i18n.differentDomains) { | ||
const options = { localDomainKey: LOCALE_DOMAIN_KEY, localeCodeKey: LOCALE_CODE_KEY } | ||
const options = { localeDomainKey: LOCALE_DOMAIN_KEY, localeCodeKey: LOCALE_CODE_KEY } | ||
const domainLocale = getLocaleDomain(locales, req, options) | ||
@@ -304,0 +307,0 @@ finalLocale = domainLocale |
@@ -15,2 +15,3 @@ import './middleware' | ||
} from './options' | ||
import { getDomainFromLocale } from './utils-common' | ||
@@ -113,17 +114,15 @@ function localePath (route, locale) { | ||
if (i18n.differentDomains) { | ||
const lang = i18n.locales.find(l => l[LOCALE_CODE_KEY] === locale) | ||
if (lang && lang[LOCALE_DOMAIN_KEY]) { | ||
let protocol | ||
if (process.server) { | ||
const isHTTPS = require('is-https') | ||
protocol = (this.req && isHTTPS(this.req)) ? 'https' : 'http' | ||
} else { | ||
protocol = window.location.protocol.split(':')[0] | ||
} | ||
path = protocol + '://' + lang[LOCALE_DOMAIN_KEY] + path | ||
} else { | ||
// eslint-disable-next-line no-console | ||
console.warn(`[${MODULE_NAME}] Could not find domain name for locale ${locale}`) | ||
const options = { | ||
differentDomains: i18n.differentDomains, | ||
locales: i18n.locales, | ||
localeDomainKey: LOCALE_DOMAIN_KEY, | ||
localeCodeKey: LOCALE_CODE_KEY, | ||
moduleName: MODULE_NAME | ||
} | ||
const domain = getDomainFromLocale(locale, this.req, options) | ||
if (domain) { | ||
path = domain + path | ||
} | ||
} | ||
return path | ||
@@ -130,0 +129,0 @@ } |
import Vue from 'vue' | ||
import { nuxtI18nSeo } from './seo-head' | ||
import { nuxtI18nSeo } from './head-meta' | ||
@@ -4,0 +4,0 @@ const plugin = { |
@@ -73,5 +73,7 @@ import Cookie from 'cookie' | ||
* @param {import('@nuxt/types').Context} context | ||
* @param {import('../../types').NuxtVueI18n.Locale} localeCode | ||
* @param {object} options | ||
* @return {string} | ||
*/ | ||
export const resolveBaseUrl = (baseUrl, context) => { | ||
export const resolveBaseUrl = (baseUrl, context, localeCode, { differentDomains, locales, localeDomainKey, localeCodeKey, moduleName }) => { | ||
if (typeof baseUrl === 'function') { | ||
@@ -81,2 +83,10 @@ return baseUrl(context) | ||
if (differentDomains && localeCode) { | ||
// Lookup the `differentDomain` origin associated with given locale. | ||
const domain = getDomainFromLocale(localeCode, context.req, { locales, localeDomainKey, localeCodeKey, moduleName }) | ||
if (domain) { | ||
return domain | ||
} | ||
} | ||
return baseUrl | ||
@@ -86,9 +96,35 @@ } | ||
/** | ||
* Gets the `differentDomain` domain from locale. | ||
* | ||
* @param {string} localeCode The locale code | ||
* @param {import('connect').IncomingMessage} [req] Request object | ||
* @param {object} options | ||
* @return {string | undefined} | ||
*/ | ||
export const getDomainFromLocale = (localeCode, req, { locales, localeDomainKey, localeCodeKey, moduleName }) => { | ||
// Lookup the `differentDomain` origin associated with given locale. | ||
const lang = locales.find(locale => locale[localeCodeKey] === localeCode) | ||
if (lang && lang[localeDomainKey]) { | ||
let protocol | ||
if (process.server) { | ||
const isHTTPS = require('is-https') | ||
protocol = (req && isHTTPS(req)) ? 'https' : 'http' | ||
} else { | ||
protocol = window.location.protocol.split(':')[0] | ||
} | ||
return `${protocol}://${lang[localeDomainKey]}` | ||
} | ||
// eslint-disable-next-line no-console | ||
console.warn(`[${moduleName}] Could not find domain name for locale ${localeCode}`) | ||
} | ||
/** | ||
* Get locale code that corresponds to current hostname | ||
* @param {object} locales | ||
* @param {object} [req] Request object | ||
* @param {{ localDomainKey: string, localeCodeKey: string }} options | ||
* @param {{ localeDomainKey: string, localeCodeKey: string }} options | ||
* @return {string | null} Locade code found if any | ||
*/ | ||
export const getLocaleDomain = (locales, req, { localDomainKey, localeCodeKey }) => { | ||
export const getLocaleDomain = (locales, req, { localeDomainKey, localeCodeKey }) => { | ||
let host = null | ||
@@ -103,3 +139,3 @@ | ||
if (host) { | ||
const matchingLocale = locales.find(l => l[localDomainKey] === host) | ||
const matchingLocale = locales.find(l => l[localeDomainKey] === host) | ||
if (matchingLocale) { | ||
@@ -106,0 +142,0 @@ return matchingLocale[localeCodeKey] |
@@ -11,2 +11,3 @@ import VueI18n from 'vue-i18n' | ||
type Strategies = 'no_prefix' | 'prefix_except_default' | 'prefix' | 'prefix_and_default' | ||
type Directions = 'ltr' | 'rtl' | 'auto' | ||
@@ -24,2 +25,3 @@ namespace Options { | ||
iso?: string | ||
dir?: Directions | ||
// can be undefined: https://goo.gl/ryc5pF | ||
@@ -59,2 +61,3 @@ file?: string | ||
defaultLocale?: Locale | ||
defaultDirection?: Directions | ||
defaultLocaleRouteNameSuffix?: string | ||
@@ -97,2 +100,15 @@ locales?: Array<Locale | LocaleObject> | ||
export interface NuxtI18nHeadOptions { | ||
/** | ||
* Adds a `dir` attribute to the HTML element. | ||
* Default: `true` | ||
*/ | ||
addDirAttribute: boolean | ||
/** | ||
* Adds various SEO attributes. | ||
* Default: `false` | ||
*/ | ||
addSeoAttributes: boolean | ||
} | ||
export interface NuxtI18nComponentOptions { | ||
@@ -99,0 +115,0 @@ paths?: { |
import Vue from 'vue' | ||
import { Location, RawLocation, Route } from 'vue-router' | ||
import VueI18n, { IVueI18n } from 'vue-i18n' | ||
import { NuxtI18nComponentOptions, NuxtVueI18n, NuxtI18nSeo } from './nuxt-i18n' | ||
import { MetaInfo } from 'vue-meta' | ||
import { NuxtI18nComponentOptions, NuxtVueI18n, NuxtI18nSeo, NuxtI18nHeadOptions } from './nuxt-i18n' | ||
@@ -27,3 +28,5 @@ /** | ||
readonly $i18n: VueI18n & IVueI18n | ||
/** @deprecated */ | ||
$nuxtI18nSeo(): NuxtI18nSeo | ||
$nuxtI18nHead(options?: NuxtI18nHeadOptions): MetaInfo | ||
getRouteBaseName(route?: Route): string | ||
@@ -30,0 +33,0 @@ localePath(route: RawLocation, locale?: string): 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
132130
1603