Skip to content

Instantly share code, notes, and snippets.

@dennyweiss
Last active March 29, 2018 11:58
Show Gist options
  • Save dennyweiss/4a3d09d7044b07fbf52ff97d116d763a to your computer and use it in GitHub Desktop.
Save dennyweiss/4a3d09d7044b07fbf52ff97d116d763a to your computer and use it in GitHub Desktop.
bookmarklet for switching languages from german to english
javascript:(function() {
/* add this code starting at 'javscript:' as address to a bookmark entry */
var currentUrl = window.location.href;
var targetUrl = null;
var BreakException = {};
var replaceMatrix = [
{ search: '/de/', replace: '/en/'},
{ search: '/de-de/', replace: '/en-us/'}
];
try {
replaceMatrix.forEach(function(item){
if (currentUrl.includes(item.search)) {
targetUrl = currentUrl.replace(item.search,item.replace);
throw BreakException;
}
});
} catch(e) {
if (e !== BreakException) {
throw e;
}
}
/*check if new target url is not null*/
if (!!targetUrl) {
window.location.href = targetUrl;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment