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

61 lines
1.1 KiB
JavaScript
Executable File

/**
* Class to manage the internationalization.
**/
Vn.Locale =
{
strings: {}
,language: null
,load: function (path, callback)
{
if (!this.language)
{
var language = navigator.language.substr (0, 2);
this.language = language ? language : 'es';
}
var file = 'locale/'+ this.language +'/'+ path +'.json'
+'?'+ Vn.Cookie.get ('hedera_version');
var request = new XMLHttpRequest ();
request.open ('get', file, true);
request.onreadystatechange = this.loadDone.bind (this, request, callback);
request.send ();
}
,loadDone: function (request, callback)
{
if (request.readyState != 4)
return;
var success = false;
if (request.status == 200)
{
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;
}