linaro-jekyll-theme 5.0.1 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c1bdd8de5ea876f98e9a2f4e44c45bfc80876a7f5ee1323d492efdf06ecc0bf
4
- data.tar.gz: 1164f51ed8abb2df3523181e46dab78a1f6f902978d13dddc92053e7fb1f5e06
3
+ metadata.gz: dae9e039186802f8d1895a3f31e57466af8df2b5093c9804102884b1d663cddf
4
+ data.tar.gz: 39b3bb094a73e3ba9b482aa587db2c9f93a8e4f0f119dc4bae786e05ed715820
5
5
  SHA512:
6
- metadata.gz: e21f998d31280cd195aa71cce2f969b3bd46afe69ada174a7dc162fb536ca612869050dbc4fe554670e94a5ed7943a6d7f62646a3bb2bfe555a10ddae88cd7d2
7
- data.tar.gz: f02a9000883c1576320cb6c6e7c61b93675819d836ca3f094910726c1f3b71c3af8dbb3bf78b3b382c758b4195c678a28ec109267cee5aa85229d7ab7f2eb8cc
6
+ metadata.gz: 1dccff4593e73d1af9ff38c052ea0103a3a6121ab9654f4980de9741ac03e4b18879480adad66a86aadfbb4d8e51eda6e22ef1304d9b9aadff39b41772c0ccc9
7
+ data.tar.gz: d2d066ca73293225eec6f235bb5200d5074abc53db605be25fc3f141de22c98ed1c400eca3aadef2f026c022feadf54fa61922ff2567dc3a7bcd4261d7ff89f9
@@ -15,9 +15,9 @@
15
15
  {% include_cached social_media_icons.html %}
16
16
  </div>
17
17
  {% if site.i18n_enabled %}
18
- <div class="col col-12 text-white text-center">
18
+ <div class="col col-12 text-white text-center" id="language_switcher">
19
19
  {% for lang in site.languages %}
20
- <a {% if lang == site.active_lang %}style="font-weight: bold;"{% endif %} {% static_href %}href="{% if lang == site.default_lang %}{{site.baseurl}}{{page.url}}{% else %}{{site.baseurl}}/{{ lang }}{{page.url}}{% endif %}"{% endstatic_href %} >{{ lang }}</a>
20
+ <a data-lang="{{lang}}" {% if lang == site.active_lang %}style="font-weight: bold;"{% endif %} href="#" class="lang_anchor">{{ lang }}</a>
21
21
  {% unless forloop.last %}
22
22
  <span class="coloured-bp">&bull;</span>
23
23
  {% endunless %}
@@ -0,0 +1,79 @@
1
+ // i18n support
2
+ $(document).ready(function () {
3
+ // Check if i18n functionality is enabled.
4
+ if ($("#language_switcher").length > 0) {
5
+ const i18n_site_versions = {
6
+ en: "/",
7
+ "en-GB": "/",
8
+ "en-US": "/",
9
+ ja: "/ja/",
10
+ };
11
+ // On click handler for language switcher.
12
+ $("#language_switcher a").on("click", function (anchor) {
13
+ anchor.preventDefault();
14
+ let lang = $(this).attr("data-lang");
15
+ console.log("Clicked lang: ", lang);
16
+ localStorage.setItem("siteLang", lang);
17
+ checkUserIsOnCorrectLanguage(lang);
18
+ });
19
+
20
+ const checkUserIsOnCorrectLanguage = (setLanguage) => {
21
+ let currentPath = window.location.pathname;
22
+ console.log("Current path:", currentPath);
23
+ // If the current path does not include the correct language sub path, redirect users to the correct version of the page.
24
+ console.log("Set lanugage: ", setLanguage);
25
+ console.log("Set language path:", i18n_site_versions[setLanguage]);
26
+ // Check to see if language subpath exists in the current path. E.g /ja/ in /ja/about/ or /about/
27
+ let hasLangInUrl = currentPath.match(/\/[A-Za-z]{2}\//g);
28
+ // Check if a lang code already exists in the pathname.
29
+ if (hasLangInUrl) {
30
+ console.log("language exists in url:", hasLangInUrl);
31
+ let newPath = currentPath.replace(
32
+ hasLangInUrl[0],
33
+ i18n_site_versions[setLanguage]
34
+ );
35
+ console.log(newPath);
36
+ if (currentPath !== newPath) {
37
+ console.log("Redirecting user to correct path: ", newPath);
38
+ window.location.href = newPath;
39
+ } else {
40
+ console.log("No redirect needed");
41
+ }
42
+ } else {
43
+ let newPath =
44
+ i18n_site_versions[setLanguage] + currentPath.substring(1);
45
+ console.log(newPath);
46
+ if (currentPath !== newPath) {
47
+ console.log("Redirecting user to correct path: ", newPath);
48
+ window.location.href = newPath;
49
+ } else {
50
+ console.log("No redirect needed");
51
+ }
52
+ }
53
+ };
54
+ // Get the current siteLang from local storage.
55
+ const currentSetLang = localStorage.getItem("siteLang");
56
+ // Get the current set lang on the browser.
57
+ var browserLang = navigator.language || navigator.userLanguage;
58
+ // Check to see if currentLang is null or not the same as the browser lang.
59
+ console.log("Current set lang:", currentSetLang);
60
+ console.log("Browser lang:", browserLang);
61
+ if (currentSetLang === null) {
62
+ console.log("No current language set or the browser lang is different.");
63
+ // Get the available locale keys.
64
+ let availableKeys = Object.keys(i18n_site_versions);
65
+
66
+ if (availableKeys.includes(browserLang)) {
67
+ localStorage.setItem("siteLang", browserLang);
68
+ checkUserIsOnCorrectLanguage(browserLang);
69
+ } else {
70
+ console.log("No alternate language available");
71
+ localStorage.setItem("siteLang", "en");
72
+ }
73
+ } else {
74
+ console.log("A current language has been set.");
75
+ // Get the current path and check that the user is on the correct version of the page.
76
+ checkUserIsOnCorrectLanguage(currentSetLang);
77
+ }
78
+ }
79
+ });
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linaro-jekyll-theme
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.1
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Kirkby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-05 00:00:00.000000000 Z
11
+ date: 2022-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll