From dbfce049fe7d7342b93f35f74f4749f4c125cdf9 Mon Sep 17 00:00:00 2001 From: Dan Yeaw Date: Sun, 16 Apr 2023 20:01:50 -0400 Subject: [PATCH 1/5] Move language selection to a drop down --- _config.yml | 2 ++ _data/languagenames.json | 10 ++++++++++ _data/languages.yml | 17 ----------------- _data/strings.yml | 2 ++ _includes/languages.html | 23 ++++++++++++++++++----- js/languages.js | 22 ++++++++++++++++++++++ 6 files changed, 54 insertions(+), 22 deletions(-) create mode 100644 _data/languagenames.json delete mode 100644 _data/languages.yml create mode 100644 js/languages.js diff --git a/_config.yml b/_config.yml index 1c6cdef8..6d4c9f6c 100644 --- a/_config.yml +++ b/_config.yml @@ -47,6 +47,7 @@ permalink: pretty include: - "_pages" + - "js" collections: usps: platforms: @@ -86,5 +87,6 @@ exclude_from_localization: - .gitignore - CNAME - css/ + - js/ - images - po/ diff --git a/_data/languagenames.json b/_data/languagenames.json new file mode 100644 index 00000000..8383eee4 --- /dev/null +++ b/_data/languagenames.json @@ -0,0 +1,10 @@ +{ + "en": "English", + "es": "Español", + "cs": "Čeština", + "nl": "Nederlands", + "hr": "Hrvatski", + "hu": "Magyar", + "ru": "Русский", + "tr": "Türkçe" +} diff --git a/_data/languages.yml b/_data/languages.yml deleted file mode 100644 index 804b24c9..00000000 --- a/_data/languages.yml +++ /dev/null @@ -1,17 +0,0 @@ -languages: - - title: English - url: "/en" - - title: Español - url: "/es" - - title: Čeština - url: "/cs" - - title: Nederlands - url: "/nl" - - title: Hrvatski - url: "/hr" - - title: Magyar - url: "/hu" - - title: Русский - url: "/ru" - - title: Türkçe - url: "/tr" diff --git a/_data/strings.yml b/_data/strings.yml index 3c8ffe82..98f7b3bd 100644 --- a/_data/strings.yml +++ b/_data/strings.yml @@ -43,3 +43,5 @@ footer: tech-docs: Tech docs copyright: Copyright © 2020-2023 Arjan Molenaar and Dan Yeaw. theme: Theme +languages: + change: Change diff --git a/_includes/languages.html b/_includes/languages.html index c34f0fb6..b7179bb4 100644 --- a/_includes/languages.html +++ b/_includes/languages.html @@ -1,7 +1,20 @@ diff --git a/js/languages.js b/js/languages.js new file mode 100644 index 00000000..e5e8747e --- /dev/null +++ b/js/languages.js @@ -0,0 +1,22 @@ + +(function() { + const chooser = document.getElementById('language-chooser-select'); + let activeLang = 'en'; + for (let i = 0; i < chooser.children.length; i++) { + if (chooser.children[i].selected) { + activeLang = chooser.children[i].value; + console.log(activeLang) + } + } + + chooser.onchange = function() { + const lang = this.value; + let pageUrl = document.location.pathname; + + if (new RegExp('^/' + activeLang + '/').test(pageUrl)) { + pageUrl = pageUrl.substring(activeLang.length + 1); + } + + document.location = '' + '/' + lang + pageUrl; + } +})(); From d0fbf7853a5ae2dfeaab3288a8e0af397ffbcf07 Mon Sep 17 00:00:00 2001 From: Dan Yeaw Date: Sun, 16 Apr 2023 20:06:37 -0400 Subject: [PATCH 2/5] Reformat code --- _includes/languages.html | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/_includes/languages.html b/_includes/languages.html index b7179bb4..aef9aa7e 100644 --- a/_includes/languages.html +++ b/_includes/languages.html @@ -1,20 +1,20 @@ From 78a9deb8714cbc084b68ac76bec36732afd3b527 Mon Sep 17 00:00:00 2001 From: Dan Yeaw Date: Sun, 16 Apr 2023 20:35:16 -0400 Subject: [PATCH 3/5] Remove function and log statement --- js/languages.js | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/js/languages.js b/js/languages.js index e5e8747e..95a505ae 100644 --- a/js/languages.js +++ b/js/languages.js @@ -1,22 +1,19 @@ -(function() { - const chooser = document.getElementById('language-chooser-select'); - let activeLang = 'en'; - for (let i = 0; i < chooser.children.length; i++) { - if (chooser.children[i].selected) { - activeLang = chooser.children[i].value; - console.log(activeLang) - } +const chooser = document.getElementById('language-chooser-select'); +let activeLang = 'en'; +for (let i = 0; i < chooser.children.length; i++) { + if (chooser.children[i].selected) { + activeLang = chooser.children[i].value; } +} - chooser.onchange = function() { - const lang = this.value; - let pageUrl = document.location.pathname; +chooser.onchange = function() { + const lang = this.value; + let pageUrl = document.location.pathname; - if (new RegExp('^/' + activeLang + '/').test(pageUrl)) { - pageUrl = pageUrl.substring(activeLang.length + 1); - } - - document.location = '' + '/' + lang + pageUrl; + if (new RegExp('^/' + activeLang + '/').test(pageUrl)) { + pageUrl = pageUrl.substring(activeLang.length + 1); } -})(); + + document.location = '' + '/' + lang + pageUrl; +} From f18e58b126e1ce9dcea4c7d2dbb228f810ce65b5 Mon Sep 17 00:00:00 2001 From: Dan Yeaw Date: Sun, 16 Apr 2023 20:35:43 -0400 Subject: [PATCH 4/5] Fix js file not found --- _includes/languages.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_includes/languages.html b/_includes/languages.html index aef9aa7e..15651061 100644 --- a/_includes/languages.html +++ b/_includes/languages.html @@ -10,7 +10,7 @@ {% endfor %} - +