Skip to content
This repository
Browse code

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

  • Loading branch information...
commit b1352187893b273cf60ee9f251aaa0e27ac7d9ba 1 parent 8320e4e
Ingo Schommer authored August 06, 2012

Showing 1 changed file with 17 additions and 5 deletions. Show diff stats Hide diff stats

  1. 22  javascript/i18n.js
22  javascript/i18n.js
@@ -22,9 +22,14 @@ ss.i18n = {
22 22
 	defaultLocale: 'en_US',
23 23
 	
24 24
 	lang: {},
  25
+
  26
+	inited: false,
25 27
 	
26 28
 	init: function() {
  29
+		if(this.inited) return;
  30
+
27 31
 		this.currentLocale = this.detectLocale();
  32
+		this.inited = true;
28 33
 	},
29 34
 	
30 35
 	/**
@@ -59,6 +64,8 @@ ss.i18n = {
59 64
 	 *
60 65
 	 */
61 66
 		_t: function (entity, fallbackString, priority, context) {
  67
+			this.init();
  68
+
62 69
 			if (this.lang && this.lang[this.getLocale()] && this.lang[this.getLocale()][entity]) {
63 70
 				return this.lang[this.getLocale()][entity];
64 71
 			} else if (this.lang && this.lang[this.defaultLocale] && this.lang[this.defaultLocale][entity]) {
@@ -165,15 +172,20 @@ ss.i18n = {
165 172
 		detectLocale: function() {
166 173
 			var rawLocale;
167 174
 			var detectedLocale;
  175
+
  176
+			// get by container tag
  177
+			rawLocale = jQuery('body').attr('lang');
168 178
 		
169 179
 			// get by meta
170  
-			var metas = document.getElementsByTagName('meta');
171  
-			for(var i=0; i<metas.length; i++) {
172  
-				if(metas[i].attributes['http-equiv'] && metas[i].attributes['http-equiv'].nodeValue.toLowerCase() == 'content-language') {
173  
-					rawLocale = metas[i].attributes['content'].nodeValue;
  180
+			if(!rawLocale) {
  181
+				var metas = document.getElementsByTagName('meta');
  182
+				for(var i=0; i<metas.length; i++) {
  183
+					if(metas[i].attributes['http-equiv'] && metas[i].attributes['http-equiv'].nodeValue.toLowerCase() == 'content-language') {
  184
+						rawLocale = metas[i].attributes['content'].nodeValue;
  185
+					}
174 186
 				}
175 187
 			}
176  
-
  188
+			
177 189
 			// fallback to default locale
178 190
 			if(!rawLocale) rawLocale = this.defaultLocale;
179 191
 			

0 notes on commit b135218

Please sign in to comment.
Something went wrong with that request. Please try again.