diff --git a/code/controller/TranslatableCMSMainExtension.php b/code/controller/TranslatableCMSMainExtension.php index d78d46d..06bdced 100644 --- a/code/controller/TranslatableCMSMainExtension.php +++ b/code/controller/TranslatableCMSMainExtension.php @@ -40,7 +40,7 @@ class TranslatableCMSMainExtension extends Extension { $req->param('Action'), $req->param('ID'), $req->param('OtherID'), - '?' . http_build_query($getVars) + ($query = http_build_query($getVars)) ? "?$query" : null )); } } diff --git a/javascript/CMSMain.Translatable.js b/javascript/CMSMain.Translatable.js index 727f357..196c17d 100755 --- a/javascript/CMSMain.Translatable.js +++ b/javascript/CMSMain.Translatable.js @@ -36,10 +36,19 @@ this._super(); }, onchange: function(e) { - var url = $.path.addSearchParams( - document.location.href.replace(/locale=[^&]*/, ''), - {locale: $(e.target).val()} - ); + // Get new locale code + locale = {locale: $(e.target).val()}; + + // Check existing url + search = /locale=[^&]*/; + url = document.location.href; + if(url.match(search)) { + // Replace locale code + url = url.replace(search, $.param(locale)); + } else { + // Add locale code + url = $.path.addSearchParams(url, locale); + } $('.cms-container').loadPanel(url); return false; }