mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUG Detect JS lang by <body>, and force init
This commit is contained in:
parent
8320e4e775
commit
b135218789
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user