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 (58 loc) · 2.06 KB
/
translation.js
File metadata and controls
66 lines (58 loc) · 2.06 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
// Removing 'nl' as of 2.3.54, pending updates
var langs = ['ca','de','en','es','fr','it','ja','nb'];
return langs;
};
AblePlayer.prototype.getTranslationText = function() {
// determine language, then get labels and prompts from corresponding translation var
var deferred, thisObj, lang, thisObj, msg, translationFile;
deferred = $.Deferred();
thisObj = this;
// 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);
}
}
}
translationFile = this.rootPath + 'translations/' + this.lang + '.js';
this.importTranslationFile(translationFile).then(function(result) {
thisObj.tt = eval(thisObj.lang);
deferred.resolve();
});
return deferred.promise();
};
AblePlayer.prototype.importTranslationFile = function(translationFile) {
var deferred = $.Deferred();
$.getScript(translationFile)
.done(function(translationVar,textStatus) {
// translation file successfully retrieved
deferred.resolve(translationVar);
})
.fail(function(jqxhr, settings, exception) {
deferred.fail();
// error retrieving file
// TODO: handle this
});
return deferred.promise();
};
})(jQuery);