Skip to content

Commit

Permalink
docs: switch language based on current path (#16687)
Browse files Browse the repository at this point in the history
* docs: switch language based on current path

ref eslint/eslint.org#380

* fix: redirect to latest when version isn't latest

* Update docs/src/_includes/components/language-switcher.html

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>

---------

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
  • Loading branch information
kecrily and mdjermanovic committed Apr 1, 2023
1 parent 24206c4 commit 518130a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/src/_data/sites/en.yml
Expand Up @@ -85,6 +85,7 @@ footer:
description: Selecting a language will take you to the ESLint website in that language.
change_language: Change Language
language: Language
latest: Latest
copyright: >
&copy; OpenJS Foundation and ESLint contributors, <a href="https://www.openjsf.org">www.openjsf.org</a>. Content licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.
links:
Expand Down
1 change: 1 addition & 0 deletions docs/src/_data/sites/zh-hans.yml
Expand Up @@ -83,6 +83,7 @@ footer:
description: 切换到你所选择语言版本对应的 ESLint 网站。
change_language: 更改语言
language: 语言
latest: 最新
copyright: >
&copy; OpenJS Foundation and ESLint contributors, <a href="https://www.openjsf.org">www.openjsf.org</a>. Content licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.
links:
Expand Down
8 changes: 6 additions & 2 deletions docs/src/_includes/components/language-switcher.html
Expand Up @@ -14,9 +14,13 @@
<select name="language selector" id="language-select" aria-describedby="language-infobox"
class="c-custom-select switcher__select">
{% for key, other_site in sites %}
<option value="{{ other_site.language.code }}" data-url="https://{{ other_site.hostname }}" {% if
site.language.code==other_site.language.code %} selected {% endif %}>
<option
value="{{ other_site.language.code }}"
data-url="https://{{ other_site.hostname }}/docs/latest{{ page.url | prettyURL }}"
{% if site.language.code==other_site.language.code %}selected{% endif %}
>
{{ other_site.language.flag }} {{ other_site.language.name }}
{% if site.language.code!=other_site.language.code or GIT_BRANCH=="latest" %}({{ other_site.footer.language_switcher.latest }}){% endif %}
</option>
{% endfor %}
</select>
Expand Down

0 comments on commit 518130a

Please sign in to comment.