Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dwardin/i18n-node into dw…
Browse files Browse the repository at this point in the history
…ardin-master
  • Loading branch information
mashpie committed Aug 19, 2020
2 parents 03501c5 + f539c23 commit 24fb9a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ i18n.configure({

// sets a custom cookie name to parse locale settings from - defaults to NULL
cookie: 'yourcookiename',

// sets a custom header name to read the language preference from - accept-language header by default
header: 'accept-language',

// query parameter to switch locale (ie. /home?lang=ch) - defaults to NULL
queryParameter: 'lang',
Expand Down
6 changes: 5 additions & 1 deletion i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const i18n = function I18n(_OPTS = false) {
pathsep = path.sep, // ---> means win support will be available in node 0.8.x and above
autoReload,
cookiename,
languageHeaderName,
defaultLocale,
retryInDefaultLocale,
directory,
Expand Down Expand Up @@ -110,6 +111,9 @@ const i18n = function I18n(_OPTS = false) {

// sets a custom cookie name to parse locale settings from
cookiename = (typeof opt.cookie === 'string') ? opt.cookie : null;

// set the custom header name to extract the language locale
languageHeaderName = (typeof opt.header === 'string') ? opt.header : 'accept-language';

// query-string parameter to be watched - @todo: add test & doc
queryParameter = (typeof opt.queryParameter === 'string') ? opt.queryParameter : null;
Expand Down Expand Up @@ -701,7 +705,7 @@ const i18n = function I18n(_OPTS = false) {

var guessLanguage = function(request) {
if (typeof request === 'object') {
var languageHeader = request.headers? request.headers['accept-language'] : undefined,
var languageHeader = request.headers? request.headers[languageHeaderName] : undefined,
languages = [],
regions = [];

Expand Down

0 comments on commit 24fb9a8

Please sign in to comment.