From 547b95cc7ae35018dadcc01b6eb1dc8c8943e67e Mon Sep 17 00:00:00 2001 From: Neil Boyd Date: Mon, 4 Mar 2024 20:09:39 +0100 Subject: [PATCH] feat(i18n): allow `page.lang` to override `site.lang` (#1586) --- _includes/js-selector.html | 2 +- _includes/lang.html | 4 +++- _layouts/default.html | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/_includes/js-selector.html b/_includes/js-selector.html index b37d710..65c6453 100644 --- a/_includes/js-selector.html +++ b/_includes/js-selector.html @@ -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: ',' diff --git a/_includes/lang.html b/_includes/lang.html index 19558a0..34b50df 100644 --- a/_includes/lang.html +++ b/_includes/lang.html @@ -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' %} diff --git a/_layouts/default.html b/_layouts/default.html index 7e355fe..6e865b9 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -13,7 +13,7 @@ layout: compress {% endif %} - + {% include head.html %} @@ -76,7 +76,7 @@ layout: compress - {% include js-selector.html %} + {% include js-selector.html lang=lang %} {% if page.mermaid %} {% include mermaid.html %}