Skip to content

Commit 69bee2d

Browse files
committed
Add language switcher
1 parent 2b952a4 commit 69bee2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+21838
-56
lines changed

_config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,6 @@ footer:
8686
- label: "Zulip"
8787
icon: "fas fa-comments"
8888
url: "https://ossci.zulipchat.com/"
89+
90+
head_scripts:
91+
- assets/js/language_switcher.js

_data/languages.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
languages:
2+
- name: English
3+
code: en
4+
url: /en/
5+
- name: Español
6+
code: es
7+
url: /es/
8+
- name: Português
9+
code: pt
10+
url: /pt/

_data/navigation.yml

Lines changed: 129 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,58 @@
11
main:
2-
- title: "Documentation"
3-
url: "https://zarr.readthedocs.io/en/stable/"
4-
- title: "Contribute"
5-
url: "https://zarr.readthedocs.io/en/stable/developers/contributing.html"
6-
- title: "Python Quickstart"
7-
url: "https://zarr.readthedocs.io/en/stable/quickstart.html"
2+
- title: "en"
3+
url: "/content/en/"
4+
children:
5+
- title: "Documentation"
6+
url: "https://zarr.readthedocs.io/en/stable/"
7+
- title: "Contribute"
8+
url: "https://zarr.readthedocs.io/en/stable/developers/contributing.html"
9+
- title: "Python Quickstart"
10+
url: "https://zarr.readthedocs.io/en/stable/quickstart.html"
11+
- title: "Language"
12+
children:
13+
- title: "English"
14+
url: "/en/"
15+
- title: "Español"
16+
url: "/es/"
17+
- title: "Português"
18+
url: "/pt/"
19+
- title: "es"
20+
url: "/content/es/"
21+
children:
22+
- title: "Documentación"
23+
url: "https://zarr.readthedocs.io/en/stable/"
24+
- title: "Contribuye"
25+
url: "https://zarr.readthedocs.io/en/stable/developers/contributing.html"
26+
- title: "Python Quickstart"
27+
url: "https://zarr.readthedocs.io/en/stable/quickstart.html"
28+
- title: "Language"
29+
children:
30+
- title: "English"
31+
url: "/en/"
32+
- title: "Español"
33+
url: "/es/"
34+
- title: "Português"
35+
url: "/pt/"
36+
- title: "pt"
37+
url: "/content/pt/"
38+
children:
39+
- title: "Documentação"
40+
url: "https://zarr.readthedocs.io/en/stable/"
41+
- title: "Contribuir"
42+
url: "https://zarr.readthedocs.io/en/stable/developers/contributing.html"
43+
- title: "Python Quickstart"
44+
url: "https://zarr.readthedocs.io/en/stable/quickstart.html"
45+
- title: "Language"
46+
children:
47+
- title: "English"
48+
url: "/en/"
49+
- title: "Español"
50+
url: "/es/"
51+
- title: "Português"
52+
url: "/pt/"
53+
854

9-
sidebar:
55+
sidebar-en:
1056
- title: About
1157
children:
1258
- title: "Description"
@@ -22,22 +68,92 @@ sidebar:
2268
- title: Subpages
2369
children:
2470
- title: "Adopters"
25-
url: "/adopters"
71+
url: "/content/en/adopters"
2672
- title: "Blog"
2773
url: '/blog'
2874
- title: "Community"
29-
url: '/community'
75+
url: '/content/en/community'
3076
- title: "Conventions"
31-
url: '/conventions'
77+
url: '/content/en/conventions'
3278
- title: "Datasets"
33-
url: '/datasets'
79+
url: '/content/en/datasets'
3480
- title: "Implementations"
35-
url: '/implementations'
81+
url: '/content/en/implementations'
3682
- title: "Office Hours"
37-
url: "/office-hours"
83+
url: "/content/en/office-hours"
3884
- title: "Slides"
3985
url: "/slides"
4086
- title: "Specification"
4187
url: https://zarr-specs.readthedocs.io/
4288
- title: "ZEPs"
4389
url: '/zeps'
90+
sidebar-es:
91+
- title: Acerca de
92+
children:
93+
- title: "Descripción"
94+
url: '#description'
95+
- title: "Aplicaciones"
96+
url: '#applications'
97+
- title: "Características"
98+
url: '#features'
99+
- title: "Patrocinio"
100+
url: "#sponsorship"
101+
- title: "Videos"
102+
url: "#videos"
103+
- title: Subpáginas
104+
children:
105+
- title: "Adoptantes"
106+
url: "/content/es/adopters"
107+
- title: "Blog"
108+
url: '/blog'
109+
- title: "Comunidad"
110+
url: '/content/es/community'
111+
- title: "Convenciones"
112+
url: '/content/es/conventions'
113+
- title: "Conjuntos de datos"
114+
url: '/content/es/datasets'
115+
- title: "Implementaciones"
116+
url: '/content/es/implementations'
117+
- title: "Oficina de horas"
118+
url: "/content/es/office-hours"
119+
- title: "Diapositivas"
120+
url: "/slides"
121+
- title: "Especificación"
122+
url: https://zarr-specs.readthedocs.io/
123+
- title: "ZEPs"
124+
url: '/zeps'
125+
sidebar-pt:
126+
- title: Sobre
127+
children:
128+
- title: "Descrição"
129+
url: '#description'
130+
- title: "Aplicações"
131+
url: '#applications'
132+
- title: "Características"
133+
url: '#features'
134+
- title: "Patrocínio"
135+
url: "#sponsorship"
136+
- title: "Vídeos"
137+
url: "#videos"
138+
- title: Subpáginas
139+
children:
140+
- title: "Adotantes"
141+
url: "/content/pt/adopters"
142+
- title: "Blog"
143+
url: '/blog'
144+
- title: "Comunidade"
145+
url: '/content/pt/community'
146+
- title: "Convenções"
147+
url: '/content/pt/conventions'
148+
- title: "Conjuntos de dados"
149+
url: '/content/pt/datasets'
150+
- title: "Implementacões"
151+
url: '/content/pt/implementations'
152+
- title: "Reuniões"
153+
url: "/content/pt/office-hours"
154+
- title: "Apresentações"
155+
url: "/slides"
156+
- title: "Especificação"
157+
url: https://zarr-specs.readthedocs.io/
158+
- title: "ZEPs"
159+
url: '/zeps'

_includes/masthead.html

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
{% capture logo_path %}{{ site.logo }}{% endcapture %}
3+
{% assign document = post | default: page %}
4+
5+
<div class="masthead">
6+
<div class="masthead__inner-wrap">
7+
<div class="masthead__menu">
8+
<nav id="site-nav" class="greedy-nav">
9+
{% unless logo_path == empty %}
10+
<a class="site-logo" href="{{ '/' | relative_url }}"><img src="{{ logo_path | relative_url }}"
11+
alt="{{ site.masthead_title | default: site.title }}"></a>
12+
{% endunless %}
13+
<a class="site-title" href="{{ '/' | relative_url }}">
14+
{{ site.masthead_title | default: site.title }}
15+
{% if site.subtitle %}<span class="site-subtitle">{{ site.subtitle }}</span>{% endif %}
16+
</a>
17+
{%- for lang in site.data.navigation.main -%}
18+
<ul class="visible-links" id="{{ lang.title }}">
19+
{%- for link in lang.children -%}
20+
{%- if link.title != "Language" -%}
21+
<li class="masthead__menu-item">
22+
<a href="{{ link.url | relative_url }}" {% if link.description %} title="{{ link.description }}" {% endif %} {% if
23+
link.target %} target="{{ link.target }}" {% endif %}>{{ link.title }}</a>
24+
</li>
25+
{%- endif -%}
26+
{%- endfor -%}
27+
</ul>
28+
{%- endfor -%}
29+
{% if site.search == true %}
30+
<button class="search__toggle" type="button">
31+
<span class="visually-hidden">{{ site.data.ui-text[site.locale].search_label | default: "Toggle
32+
search" }}</span>
33+
<i class="fas fa-search"></i>
34+
</button>
35+
{% endif %}
36+
<div class="masthead__dropdown" style="display: flex;">
37+
<span class="visually-hidden">{{ site.data.ui-text[site.locale].search_label | default: "Toggle
38+
search" }}</span>
39+
<select class="masthead__dropdown-select" style="box-shadow: none; background-color: unset; margin-bottom: 0px;" onchange="change_language()" id="select_language">
40+
{% for lang in site.data.languages.languages %}
41+
<option value="/content{{ lang.url | relative_url }}">{{ lang.name }}</option>
42+
{% endfor %}
43+
</select>
44+
</div>
45+
<button class="greedy-nav__toggle hidden" type="button">
46+
<span class="visually-hidden">{{ site.data.ui-text[site.locale].menu_label | default: "Toggle menu"
47+
}}</span>
48+
<div class="navicon"></div>
49+
</button>
50+
<ul class="hidden-links hidden"></ul>
51+
</nav>
52+
</div>
53+
</div>
54+
</div>

assets/js/language_switcher.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
window.addEventListener("DOMContentLoaded", function() {
2+
let current_language = localStorage.getItem("current_language");
3+
if (current_language === null) {
4+
// No language set, defaulting to English
5+
current_language = "/content/en";
6+
}
7+
// Set the option in the select element to have the "selected" attribute
8+
var selectElement = document.getElementById("select_language");
9+
var selectedOption = selectElement.querySelector(
10+
'option[value="' + current_language + '"]'
11+
);
12+
if (selectedOption) {
13+
selectedOption.setAttribute("selected", "");
14+
}
15+
// Remove items from navigation which do not correpond to current language
16+
const navlist = document.getElementsByClassName("visible-links");
17+
Array.from(navlist).forEach(element => {
18+
if (element.id !== current_language.split("/")[2]) {
19+
const parent = element.parentNode;
20+
if (parent) {
21+
parent.removeChild(element);
22+
}
23+
}
24+
});
25+
});
26+
27+
// Change language for current page
28+
function change_language() {
29+
var selectElement = document.getElementById("select_language");
30+
var value = selectElement.options[selectElement.selectedIndex].value;
31+
// Get the current page URL
32+
const currentPageUrl = window.location.href;
33+
const old_language = localStorage.getItem("current_language");
34+
localStorage.setItem("current_language", value);
35+
// Update the lang attribute of the HTML element
36+
document.documentElement.setAttribute("lang", value.split("/")[2]);
37+
window.location.href = currentPageUrl.replace(
38+
old_language,
39+
value
40+
);
41+
}
File renamed without changes.

adopters/index.md renamed to content/en/adopters/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author_profile: false
44
title: Zarr Adopters
55
sidebar:
66
title: "Content"
7-
nav: sidebar
7+
nav: sidebar-en
88
---
99

1010
<p style="font-family:Trebuchet MS"><font size="4">💡 If you're using Zarr in any way and would like to be added on this page, please drop your logo and blurb <a href="https://github.com/zarr-developers/community/issues/60">here</a>.</font></p>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 35 additions & 35 deletions
Loading
File renamed without changes.
File renamed without changes.

community/index.md renamed to content/en/community/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author_profile: false
44
title: Zarr Community
55
sidebar:
66
title: "Content"
7-
nav: sidebar
7+
nav: sidebar-en
88
---
99

1010
Zarr is a community-driven open-source data format specification developed and maintained by diverse [contributors](https://github.com/orgs/zarr-developers/teams). The Zarr contributors aim to maintain an open, equal, diverse, and inclusive community. Please read the [Zarr Code of Conduct](https://github.com/zarr-developers/.github/blob/main/CODE_OF_CONDUCT.md) for the appropriate way to interact with the community and help each other.

conventions/index.md renamed to content/en/conventions/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author_profile: false
44
title: Zarr Conventions
55
sidebar:
66
title: "Content"
7-
nav: sidebar
7+
nav: sidebar-en
88
---
99

1010
<font size="4">

datasets/index.md renamed to content/en/datasets/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author_profile: false
44
title: Zarr Datasets
55
sidebar:
66
title: "Content"
7-
nav: sidebar
7+
nav: sidebar-en
88
---
99

1010
<font size="4">

implementations/index.md renamed to content/en/implementations/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author_profile: false
44
title: Zarr Implementations
55
sidebar:
66
title: "Content"
7-
nav: sidebar
7+
nav: sidebar-en
88
---
99

1010
<font size="4">

0 commit comments

Comments
 (0)