hedera-web/web/js/vn/locale.js

71 lines
1.2 KiB
JavaScript
Raw Normal View History

/**
* Class to manage the internationalization.
**/
Vn.Locale =
{
strings: {}
,language: null
,init: function ()
{
if (!this.language)
{
var language = navigator.language.substr (0, 2);
2015-01-31 01:05:12 +00:00
this.language = language ? language : 'es';
}
}
,load: function (path, callback)
{
this.init ();
var file = 'locale/'+ this.language +'/'+ path +'.json'+ Vn.getVersion ();
var request = new XMLHttpRequest ();
request.open ('get', file, true);
request.onreadystatechange = this.loadDone.bind (this, request, callback);
request.send ();
}
,loadScript: function (path, callback)
{
this.init ();
Vn.includeJs ('locale/'+ this.language +'/'+ path, callback);
}
,loadDone: function (request, callback)
{
if (request.readyState != 4)
return;
2015-02-17 11:48:53 +00:00
var success = false;
if (request.status == 200)
2015-02-17 11:48:53 +00:00
{
try {
this.add (eval ('('+ request.responseText +')'));
success = true;
}
catch (e) {
console.log ('Locale: %s', e);
}
}
callback (success);
}
,add: function (strings)
{
for (var stringId in strings)
this.strings[stringId] = strings[stringId];
}
}
function _(stringId)
{
var string = Vn.Locale.strings[stringId];
return (string) ? string : stringId;
}