From 66caa9f870dbf7a6c4fb14827761942031b1cf0c Mon Sep 17 00:00:00 2001 From: hellekin Date: Sat, 6 Jan 2018 10:46:53 +0100 Subject: Allow passing ?lang=en to switch to English (or fr for French) --- assets/js/ps-app.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'assets/js') diff --git a/assets/js/ps-app.js b/assets/js/ps-app.js index 7675ec4..33f4f99 100644 --- a/assets/js/ps-app.js +++ b/assets/js/ps-app.js @@ -28,15 +28,26 @@ .append('') $('#lang-switch').click(function(e) { var lang = $('html').attr('lang') + setLang(lang == 'fr' ? 'en' : 'fr') + return false + }) + + // Use ?lang=XX if available + var URLParams = new URLSearchParams(window.location.search); + if (URLParams.has('lang')) { + setLang(URLParams.get('lang')) + } + + // Translate to target lang + function setLang(lang) { if (lang == 'fr') { - $('html').attr('lang', 'en') - $(e.target).html('FR').attr('title', 'Lire en français') - } else { $('html').attr('lang', 'fr') - $(e.target).html('EN').attr('title', 'Read in English') + $('#lang-switch').html('EN').attr('title', 'Read in English') + } else { + $('html').attr('lang', 'en') + $('#lang-switch').html('FR').attr('title', 'Lire en français') } - return false - }) + } }); -- cgit v1.2.3