nuxt-i18n
Advanced tools
Comparing version 6.17.0 to 6.18.0
@@ -0,1 +1,9 @@ | ||
## [6.18.0](https://github.com/nuxt-community/i18n-module/compare/v6.17.0...v6.18.0) (2021-01-13) | ||
### Features | ||
* expose API for detecting browser locale ([#1022](https://github.com/nuxt-community/i18n-module/issues/1022)) ([ac75635](https://github.com/nuxt-community/i18n-module/commit/ac75635d963104498e876040b111dd8d16fef6d3)), closes [#1018](https://github.com/nuxt-community/i18n-module/issues/1018) | ||
* expose localeProperties property ([#1016](https://github.com/nuxt-community/i18n-module/issues/1016)) ([a9457a0](https://github.com/nuxt-community/i18n-module/commit/a9457a02177e230ec4529a96b97b3aa2993b9ec2)), closes [#916](https://github.com/nuxt-community/i18n-module/issues/916) | ||
## [6.17.0](https://github.com/nuxt-community/i18n-module/compare/v6.16.0...v6.17.0) (2021-01-05) | ||
@@ -2,0 +10,0 @@ |
{ | ||
"name": "nuxt-i18n", | ||
"version": "6.17.0", | ||
"version": "6.18.0", | ||
"description": "i18n for Nuxt", | ||
@@ -104,3 +104,3 @@ "license": "MIT", | ||
"@types/finalhandler": "1.1.0", | ||
"@types/jest": "26.0.19", | ||
"@types/jest": "26.0.20", | ||
"@types/jest-dev-server": "4.2.0", | ||
@@ -107,0 +107,0 @@ "@types/jsdom": "16.2.5", |
@@ -117,2 +117,3 @@ import Vue from 'vue' | ||
app.i18n.locale = newLocale | ||
app.i18n.localeProperties = klona(locales.find(l => l[LOCALE_CODE_KEY] === newLocale) || { code: newLocale }) | ||
@@ -203,2 +204,13 @@ await syncVuex(store, newLocale, app.i18n.getLocaleMessage(newLocale), { vuex }) | ||
const getBrowserLocale = () => { | ||
if (process.client && typeof navigator !== 'undefined' && navigator.languages) { | ||
// Get browser language either from navigator if running on client side, or from the headers | ||
return matchBrowserLocale(locales, navigator.languages) | ||
} else if (req && typeof req.headers['accept-language'] !== 'undefined') { | ||
return matchBrowserLocale(locales, parseAcceptLanguage(req.headers['accept-language'])) | ||
} else { | ||
return undefined | ||
} | ||
} | ||
const doDetectBrowserLanguage = route => { | ||
@@ -226,7 +238,5 @@ // Browser detection is ignored if it is a nuxt generate. | ||
// Get preferred language from cookie if present and enabled | ||
} else if (process.client && typeof navigator !== 'undefined' && navigator.languages) { | ||
// Get browser language either from navigator if running on client side, or from the headers | ||
matchedLocale = matchBrowserLocale(locales, navigator.languages) | ||
} else if (req && typeof req.headers['accept-language'] !== 'undefined') { | ||
matchedLocale = matchBrowserLocale(locales, parseAcceptLanguage(req.headers['accept-language'])) | ||
} else { | ||
// Try to get locale from either navigator or header detection | ||
matchedLocale = getBrowserLocale() | ||
} | ||
@@ -255,2 +265,3 @@ | ||
i18n.setLocale = (locale) => loadAndSetLocale(locale) | ||
i18n.getBrowserLocale = () => getBrowserLocale() | ||
i18n.__baseUrl = app.i18n.__baseUrl | ||
@@ -265,2 +276,3 @@ } | ||
app.i18n.locale = '' | ||
app.i18n.localeProperties = { code: '' } | ||
app.i18n.fallbackLocale = vueI18nOptions.fallbackLocale || '' | ||
@@ -267,0 +279,0 @@ extendVueI18nInstance(app.i18n) |
@@ -22,3 +22,3 @@ import Cookie from 'cookie' | ||
* @param {string[]} browserLocales The locales to match against configured. | ||
* @return {string?} | ||
* @return {string|undefined} | ||
*/ | ||
@@ -67,3 +67,3 @@ export const matchBrowserLocale = (appLocales, browserLocales) => { | ||
return matchedLocales.length ? matchedLocales[0].code : null | ||
return matchedLocales.length ? matchedLocales[0].code : undefined | ||
} | ||
@@ -70,0 +70,0 @@ |
@@ -13,5 +13,7 @@ import Vue from 'vue' | ||
interface IVueI18n extends NuxtVueI18n.Options.NuxtI18nInterface { | ||
localeProperties: NuxtVueI18n.Options.LocaleObject | ||
getLocaleCookie() : string | undefined | ||
setLocaleCookie(locale: string) : undefined | ||
setLocale(locale: string) : Promise<undefined> | ||
getBrowserLocale() : string | undefined | ||
} | ||
@@ -18,0 +20,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
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
128035
1525