2015-01-23 13:09:30 +00:00
|
|
|
/**
|
|
|
|
* Class to manage the internationalization.
|
|
|
|
**/
|
|
|
|
Vn.Locale =
|
|
|
|
{
|
|
|
|
strings: {}
|
|
|
|
|
|
|
|
,language: null
|
|
|
|
|
2015-09-11 09:37:16 +00:00
|
|
|
,init: function ()
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
|
|
|
if (!this.language)
|
|
|
|
{
|
|
|
|
var language = navigator.language.substr (0, 2);
|
2015-11-19 13:57:23 +00:00
|
|
|
this.language = language ? language : 'en';
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
2015-09-11 09:37:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,load: function (path, callback)
|
|
|
|
{
|
|
|
|
this.init ();
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2015-09-25 13:35:01 +00:00
|
|
|
var file = 'locale/'+ this.language +'/'+ path +'.json'+ Vn.getVersion ();
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
var request = new XMLHttpRequest ();
|
|
|
|
request.open ('get', file, true);
|
|
|
|
request.onreadystatechange = this.loadDone.bind (this, request, callback);
|
|
|
|
request.send ();
|
|
|
|
}
|
2015-09-11 09:37:16 +00:00
|
|
|
|
|
|
|
,loadScript: function (path, callback)
|
|
|
|
{
|
|
|
|
this.init ();
|
|
|
|
Vn.includeJs ('locale/'+ this.language +'/'+ path, callback);
|
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
,loadDone: function (request, callback)
|
|
|
|
{
|
|
|
|
if (request.readyState != 4)
|
|
|
|
return;
|
2015-02-17 11:48:53 +00:00
|
|
|
|
|
|
|
var success = false;
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
if (request.status == 200)
|
2015-02-17 11:48:53 +00:00
|
|
|
{
|
|
|
|
try {
|
2016-07-22 22:36:38 +00:00
|
|
|
this.add (JSON.parse (request.responseText));
|
2015-02-17 11:48:53 +00:00
|
|
|
success = true;
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
console.log ('Locale: %s', e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
callback (success);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,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;
|
|
|
|
}
|
|
|
|
|