diff options
author | hellekin <hellekin@cepheide.org> | 2018-01-06 10:46:53 +0100 |
---|---|---|
committer | hellekin <hellekin@cepheide.org> | 2018-01-06 10:46:53 +0100 |
commit | 66caa9f870dbf7a6c4fb14827761942031b1cf0c (patch) | |
tree | f554e07372343dc47dae02ca776d05241edfebc3 /assets/js/ps-app.js | |
parent | 39f3f2b2519ec0de27a53f9237080718a01491fb (diff) | |
download | lesoiseaux.io-66caa9f870dbf7a6c4fb14827761942031b1cf0c.tar.gz |
Allow passing ?lang=en to switch to English (or fr for French)
Diffstat (limited to 'assets/js/ps-app.js')
-rw-r--r-- | assets/js/ps-app.js | 23 |
1 files changed, 17 insertions, 6 deletions
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('<button id="lang-switch" title="Read in English">EN</button>') $('#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 - }) + } }); |