aboutsummaryrefslogtreecommitdiff
path: root/assets/js
diff options
context:
space:
mode:
authorhellekin <hellekin@cepheide.org>2018-01-06 10:46:53 +0100
committerhellekin <hellekin@cepheide.org>2018-01-06 10:46:53 +0100
commit66caa9f870dbf7a6c4fb14827761942031b1cf0c (patch)
treef554e07372343dc47dae02ca776d05241edfebc3 /assets/js
parent39f3f2b2519ec0de27a53f9237080718a01491fb (diff)
downloadlesoiseaux.io-66caa9f870dbf7a6c4fb14827761942031b1cf0c.tar.gz
Allow passing ?lang=en to switch to English (or fr for French)
Diffstat (limited to 'assets/js')
-rw-r--r--assets/js/ps-app.js23
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
- })
+ }
});