function selectLanguage () {
var languages = ['de', 'en', 'fr'];
var defaultLang = 'en';
var newUri = false;
for ( var i=0; i < languages.length; i++ ) {
if ( navigator.language.indexOf( languages[i] ) > -1 ) {
newUri = constructNewUri( languages[i] );
}
}
if ( false == newUri ) {
newUri = constructNewUri( defaultLang );
}
document.location.href = newUri;
}
function constructNewUri( language ) {
var uri = new URL( document.location.href );
uri.pathname = '/' + language + uri.pathname;
return uri.href;
}
selectLanguage();