Skip to content

Commit

Permalink
feat(i18n): allow page.lang to override site.lang (cotes2020#1586)
Browse files Browse the repository at this point in the history
  • Loading branch information
neilboyd authored and gudtldn committed Jul 26, 2024
1 parent ea93629 commit 7be6525
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion _includes/js-selector.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
or page.layout == 'category'
or page.layout == 'tag'
%}
{% assign locale = site.lang | split: '-' | first %}
{% assign locale = include.lang | split: '-' | first %}

{% assign urls = urls
| append: ','
Expand Down
4 changes: 3 additions & 1 deletion _includes/lang.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{% comment %}
Detect appearance language and return it through variable "lang"
{% endcomment %}
{% if site.data.locales[site.lang] %}
{% if site.data.locales[page.lang] %}
{% assign lang = page.lang %}
{% elsif site.data.locales[site.lang] %}
{% assign lang = site.lang %}
{% else %}
{% assign lang = 'en' %}
Expand Down
4 changes: 2 additions & 2 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{% endif %}

<!-- `site.alt_lang` can specify a language different from the UI -->
<html lang="{{ site.alt_lang | default: site.lang }}" {{ prefer_mode }}>
<html lang="{{ page.lang | default: site.alt_lang | default: site.lang }}" {{ prefer_mode }}>
{% include head.html %}

<body>
Expand Down Expand Up @@ -76,7 +76,7 @@

<!-- JavaScripts -->

{% include js-selector.html %}
{% include js-selector.html lang=lang %}

{% if page.mermaid %}
{% include mermaid.html %}
Expand Down

0 comments on commit 7be6525

Please sign in to comment.