From 95355f90360aee56cd188440815dd9d08545836a Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 20 Jan 2014 11:04:06 -0500 Subject: [PATCH] added 'dir' value into language.json, added support for translator to add dir attribute to html element if necessary --- public/language/ar/language.json | 3 ++- public/src/translator.js | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/public/language/ar/language.json b/public/language/ar/language.json index f11cc8d293..b494e3901a 100644 --- a/public/language/ar/language.json +++ b/public/language/ar/language.json @@ -1,4 +1,5 @@ { "name": "العربية", - "code": "ar" + "code": "ar", + "dir": "rtl" } \ No newline at end of file diff --git a/public/src/translator.js b/public/src/translator.js index 60994696b6..afc726d446 100644 --- a/public/src/translator.js +++ b/public/src/translator.js @@ -47,8 +47,15 @@ $.getScript(RELATIVE_PATH + '/vendor/jquery/timeago/locales/jquery.timeago.' + languageCode + '.js').fail(function() { $.getScript(RELATIVE_PATH + '/vendor/jquery/timeago/locales/jquery.timeago.en.js'); }); + + // Add directional code if necessary + translator.get('language:dir', function(value) { + if (value) { + $('html').attr('dir', value); + } + }); } - } + }; translator.get = function (key, callback) { var parsedKey = key.split(':'), @@ -76,7 +83,7 @@ } async.map(keys, getKey, callback); - } + }; translator.translate = function (data, callback) { var keys = data.match(/\[\[.*?\]\]/g), @@ -103,7 +110,9 @@ var variables = keys[key].split(/[,][?\s+]/); var parsedKey = keys[key].replace('[[', '').replace(']]', '').split(':'); - if (!(parsedKey[0] && parsedKey[1])) continue; + if (!(parsedKey[0] && parsedKey[1])) { + continue; + } var languageFile = parsedKey[0]; parsedKey = parsedKey[1].split(',')[0];