/
l10n.js
35 lines (35 loc) · 1008 Bytes
/
l10n.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// LICENCE https://github.com/adaptlearning/adapt_authoring/blob/master/LICENSE
define(['require', 'jquery', 'polyglot', 'core/origin'], function(require, $, Polyglot, Origin) {
var polyglot;
// set up global l10n object
Origin.l10n = {
t: function(string, data) {
if(!polyglot || !polyglot.t) {
return string;
}
return polyglot.t.apply(polyglot, arguments);
},
has: function() {
if(!polyglot || !polyglot.has) {
return false;
}
return polyglot.has.apply(polyglot, arguments);
}
};
/**
* Initialise from language file
*/
var locale = localStorage.getItem('lang') || 'en';
$.getJSON('lang/' + locale, function(data) {
polyglot = new Polyglot({
locale: locale,
phrases: data,
warn: function(message) {
if(Origin.debug) console.warn('l10n:', message);
}
});
Origin.trigger('l10n:loaded');
}).fail(function(jqXHR, textStatus, error) {
Origin.trigger('l10n:loaded');
});
});