diff --git a/README.md b/README.md index 8003ec6b..2308d485 100644 --- a/README.md +++ b/README.md @@ -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', diff --git a/i18n.js b/i18n.js index d4f6fcb5..80312562 100644 --- a/i18n.js +++ b/i18n.js @@ -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, @@ -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; @@ -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 = [];