Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

BUG Detect JS lang by <body>, and force init

  • Loading branch information...
commit b1352187893b273cf60ee9f251aaa0e27ac7d9ba 1 parent 8320e4e
@chillu chillu authored
Showing with 17 additions and 5 deletions.
  1. +17 −5 javascript/i18n.js
View
22 javascript/i18n.js
@@ -22,9 +22,14 @@ ss.i18n = {
defaultLocale: 'en_US',
lang: {},
+
+ inited: false,
init: function() {
+ if(this.inited) return;
+
this.currentLocale = this.detectLocale();
+ this.inited = true;
},
/**
@@ -59,6 +64,8 @@ ss.i18n = {
*
*/
_t: function (entity, fallbackString, priority, context) {
+ this.init();
+
if (this.lang && this.lang[this.getLocale()] && this.lang[this.getLocale()][entity]) {
return this.lang[this.getLocale()][entity];
} else if (this.lang && this.lang[this.defaultLocale] && this.lang[this.defaultLocale][entity]) {
@@ -165,15 +172,20 @@ ss.i18n = {
detectLocale: function() {
var rawLocale;
var detectedLocale;
+
+ // get by container tag
+ rawLocale = jQuery('body').attr('lang');
// get by meta
- var metas = document.getElementsByTagName('meta');
- for(var i=0; i<metas.length; i++) {
- if(metas[i].attributes['http-equiv'] && metas[i].attributes['http-equiv'].nodeValue.toLowerCase() == 'content-language') {
- rawLocale = metas[i].attributes['content'].nodeValue;
+ if(!rawLocale) {
+ var metas = document.getElementsByTagName('meta');
+ for(var i=0; i<metas.length; i++) {
+ if(metas[i].attributes['http-equiv'] && metas[i].attributes['http-equiv'].nodeValue.toLowerCase() == 'content-language') {
+ rawLocale = metas[i].attributes['content'].nodeValue;
+ }
}
}
-
+
// fallback to default locale
if(!rawLocale) rawLocale = this.defaultLocale;
Please sign in to comment.
Something went wrong with that request. Please try again.