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
71 lines (65 loc) · 2.01 KB
/
translation.js
File metadata and controls
71 lines (65 loc) · 2.01 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
67
68
69
70
71
(function ($) {
AblePlayer.prototype.getSupportedLangs = function() {
// returns an array of languages for which AblePlayer has translation tables
var langs = ['ca','de','en','es','fr','he','it','ja','nb','nl','pt-br','tr','zh-tw'];
return langs;
};
AblePlayer.prototype.getTranslationText = function() {
// determine language, then get labels and prompts from corresponding translation var
var deferred, thisObj, lang, thisObj, msg, translationFile, collapsedLang;
deferred = $.Deferred();
thisObj = this;
// get language of the web page, if specified
if ($('body').attr('lang')) {
lang = $('body').attr('lang');
}
else if ($('html').attr('lang')) {
lang = $('html').attr('lang');
}
else {
lang = null;
}
// override this.lang to language of the web page, if known and supported
// otherwise this.lang will continue using default
if (!this.forceLang) {
if (lang) {
if (lang !== this.lang) {
if ($.inArray(lang,this.getSupportedLangs()) !== -1) {
// this is a supported lang
this.lang = lang;
}
else {
msg = lang + ' is not currently supported. Using default language (' + this.lang + ')';
if (this.debug) {
console.log(msg);
}
}
}
}
}
if (!this.searchLang) {
this.searchLang = this.lang;
}
translationFile = this.rootPath + 'translations/' + this.lang + '.js';
this.importTranslationFile(translationFile).then(function(result) {
collapsedLang = thisObj.lang.replace('-','');
thisObj.tt = eval(collapsedLang);
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);