nuxt-i18n
Advanced tools
Comparing version 2.5.1 to 2.6.0
@@ -5,2 +5,12 @@ # Change Log | ||
<a name="2.6.0"></a> | ||
# [2.6.0](https://github.com/nuxt-community/nuxt-i18n/compare/v2.5.1...v2.6.0) (2018-03-10) | ||
### Features | ||
* Add useRedirectCookie option ([6d6aad0](https://github.com/nuxt-community/nuxt-i18n/commit/6d6aad0)) | ||
<a name="2.5.1"></a> | ||
@@ -7,0 +17,0 @@ ## [2.5.1](https://github.com/nuxt-community/nuxt-i18n/compare/v2.5.0...v2.5.1) (2018-03-10) |
@@ -15,3 +15,4 @@ const { resolve } = require('path') | ||
detectBrowserLanguage: false, | ||
redirectCookieKey: 'redirected' | ||
redirectCookieKey: 'redirected', | ||
useRedirectCookie: true | ||
} | ||
@@ -18,0 +19,0 @@ const options = merge(defaults, moduleOptions, this.options.i18n) |
import cookie from 'cookie' | ||
import { has } from 'lodash' | ||
import middleware from './middleware' | ||
@@ -22,14 +21,16 @@ | ||
if (<%= options.detectBrowserLanguage %> && req && route.name) { | ||
const cookieKey = '<%= options.redirectCookieKey %>'; | ||
const cookies = has(req, 'headers.cookie') ? cookie.parse(req.headers.cookie) : {}; | ||
const useRedirectCookie = <%= options.useRedirectCookie %> | ||
const cookieKey = '<%= options.redirectCookieKey %>' | ||
const cookies = req.headers && req.headers.cookies ? | ||
cookie.parse(req.headers.cookie) : {} | ||
// Redirect only if cookie not set yet | ||
if (!cookies[cookieKey]) { | ||
if (!cookies[cookieKey] || !useRedirectCookie) { | ||
const browserLocale = req.headers['accept-language'].split(',')[0].toLocaleLowerCase().substring(0, 2) | ||
// Set cookie | ||
if (res) { | ||
const date = new Date(); | ||
if (useRedirectCookie && res) { | ||
const date = new Date() | ||
const redirectCookie = cookie.serialize(cookieKey, 1, { | ||
expires: new Date(date.setDate(date.getDate() + 365)) | ||
}) | ||
res.setHeader('Set-Cookie', redirectCookie); | ||
res.setHeader('Set-Cookie', redirectCookie) | ||
} | ||
@@ -41,3 +42,3 @@ // Redirect | ||
name: app.getRouteBaseName() | ||
}))); | ||
}))) | ||
} | ||
@@ -44,0 +45,0 @@ } |
{ | ||
"name": "nuxt-i18n", | ||
"version": "2.5.1", | ||
"version": "2.6.0", | ||
"description": "i18n for Nuxt", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
32290
351