-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlang-script.js
More file actions
45 lines (36 loc) · 1.35 KB
/
lang-script.js
File metadata and controls
45 lines (36 loc) · 1.35 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
var supported_lang = ['en','it','ja', 'es', 'pt', 'he', 'tr', 'ar', 'fr'];
$(document).ready(function() {
var language = navigator.languages && navigator.languages[0] || // Chrome / Firefox
navigator.language || // All browsers
navigator.userLanguage; // IE <= 10
// Don't add language if empty or not supported.
if (!language || supported_lang.indexOf(language.substr(0,2)) == -1){
return;
}
$(".youtube-iframe").attr("detected-b-lang", language);
// update iframe src
$('.youtube-iframe').attr('src', function(i, val){
// Only add language if isn't set up (by Transifex)
if (val.indexOf("&hl=") == -1) {
val = val + '&hl=' + language;
}
if (val.indexOf("&cc_lang_pref=") == -1) {
val = val + '&cc_lang_pref=' + language;
}
return val;
});
});
Transifex.live.onTranslatePage(function(language_code) {
var new_lang = Transifex.live.getSelectedLanguageCode();
if (new_lang) {
$(".youtube-iframe").attr("tr-lang", new_lang);
if (supported_lang.indexOf(new_lang.substr(0,2)) != -1) {
// add new language
$('.youtube-iframe').attr('src', function(i, val){
// remove last lang if exists
val = val.replace(/&hl=.*/, '').replace(/&cc_lang_pref=.*/, '');
return val + '&hl=' + new_lang + '&cc_lang_pref=' + new_lang;
});
}
}
});