Skip to content
Permalink
Browse files

Enhance our locale middleware to determite directionality

  • Loading branch information...
lmarkus committed May 30, 2015
1 parent 3bce161 commit eecc1392dbe89e0ccecac99fdc6f7b1d3586242e
Showing with 23 additions and 3 deletions.
  1. +23 −3 lib/locale.js
@@ -1,11 +1,31 @@
'use strict';

//RTL Language list sourced from: http://en.wikipedia.org/wiki/Right-to-left#RTL_Wikipedia_languages
var rtlLanguages =
['ar', 'arc', 'bcc', 'bqi', 'ckb', 'dv', 'fa', 'glk', 'he', 'ku', 'mzn', 'pnb', 'ps', 'sd', 'ug', 'ur', 'yi'];

module.exports = function () {
return function (req, res, next) {
var locale = req.cookies && req.cookies.locale;
var locale = ((req.cookies && req.cookies.locale) || 'en_US').split('_'),

//Extract the language portion of the locale. E.g.: en_US -> en
language = locale[0],

//Extract the country portion of the locale. E.g.: en_US -> US
country = locale[1],

//Check if language belongs to the RTL group.
directionality = rtlLanguages.lastIndexOf(language) >= 0 ? 'rtl' : 'ltr';

//Set the locality for this response. The template will pick the appropriate bundle
res.locals.context = {
locality: locale
locality: {
language: language,
country: country,
directionality: directionality
}
};
next();
};
};
};

0 comments on commit eecc139

Please sign in to comment.
You can’t perform that action at this time.