-
-
Notifications
You must be signed in to change notification settings - Fork 64
/
redirect.js
34 lines (25 loc) · 904 Bytes
/
redirect.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
function getLanguageFolder() {
var supported = ['id', 'ca', 'cs', 'de', 'es', 'fr', 'gl', 'it', 'nl',
'pl', 'pt', 'pt_BR', 'sq', 'sk', 'tr', 'ru', 'uk', 'zh_CN'];
var desired = navigator.language || navigator.userLanguage;
desired = desired.replace('-', '_');
if (supported.indexOf(desired) != -1) {
return desired;
}
desired = desired.split('_')[0].toLowerCase();
if (supported.indexOf(desired) != -1) {
return desired;
}
return 'en'
}
function getRedirectFile() {
var metaTag = document.querySelector('meta[http-equiv="refresh"]');
var content = metaTag.getAttribute('content');
var urlMatch = content.match(/url\s*=\s*en\/([^;]+)/i);
if (urlMatch && urlMatch[1]) {
return urlMatch[1].trim();
}
return '';
}
var newLocation = getLanguageFolder() + '/' + getRedirectFile() + window.location.hash;
window.location.href = newLocation;