forked from ableplayer/ableplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranslation.js
More file actions
66 lines (63 loc) · 2.2 KB
/
translation.js
File metadata and controls
66 lines (63 loc) · 2.2 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
(function ($) {
AblePlayer.prototype.getSupportedLangs = function() {
// returns an array of languages for which AblePlayer has translation tables
var langs = ['en','de','es'];
return langs;
};
AblePlayer.prototype.getTranslationText = function() {
// determine language, then get labels and prompts from corresponding translation file (in JSON)
// finally, populate this.tt object with JSON data
// return true if successful, otherwise false
var gettingText, lang, thisObj, msg;
gettingText = $.Deferred();
// override this.lang to language of the web page, if known and supported
// otherwise this.lang will continue using default
if (!this.forceLang) {
if ($('body').attr('lang')) {
lang = $('body').attr('lang');
}
else if ($('html').attr('lang')) {
lang = $('html').attr('lang');
}
if (lang !== this.lang) {
msg = 'Language of web page (' + lang +') ';
if ($.inArray(lang,this.getSupportedLangs()) !== -1) {
// this is a supported lang
msg += ' has a translation table available.';
this.lang = lang;
}
else {
msg += ' is not currently supported. Using default language (' + this.lang + ')';
}
if (this.debug) {
console.log(msg);
}
}
}
thisObj = this;
// get content of JSON file
$.getJSON(this.translationPath + this.lang + '.js',
function(data, textStatus, jqxhr) {
if (textStatus === 'success') {
thisObj.tt = data;
if (thisObj.debug) {
console.log('Successfully assigned JSON data to trans');
console.log(thisObj.tt);
}
}
else {
return false;
}
}
).then(
function(){ // success
// resolve deferred variable
gettingText.resolve();
},
function() { // failure
return false;
}
);
return gettingText.promise();
};
})(jQuery);