From 63e21f0fe005e20ed52ff4cc2f269f95e84a974a Mon Sep 17 00:00:00 2001 From: Cyril MARPAUD Date: Tue, 14 Mar 2023 10:38:08 +0100 Subject: [PATCH] feat: support multilingual sites --- static/style.css | 14 ++++++++++++++ templates/base.html | 6 +++--- templates/cards/list.html | 2 +- templates/index.html | 21 ++++++++++++++++++--- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/static/style.css b/static/style.css index d659b3c..fae6f25 100644 --- a/static/style.css +++ b/static/style.css @@ -44,6 +44,20 @@ body { margin: auto; } +#lang { + position: absolute; + top: 1%; + right: 1%; + margin: 0.5em; + font-size: 1.5em; +} + +#lang a { + color: white; + font-variant: small-caps; + text-decoration: none; +} + #name { display: inline; font-size: 7em; diff --git a/templates/base.html b/templates/base.html index cdfb05a..c224fe7 100644 --- a/templates/base.html +++ b/templates/base.html @@ -3,7 +3,7 @@ {% set author = macro::format_name(name=config.extra.name) | striptags -%} - + @@ -12,7 +12,7 @@ - + {{ author }} @@ -24,7 +24,7 @@ \ No newline at end of file diff --git a/templates/cards/list.html b/templates/cards/list.html index e134dc1..bdec63f 100644 --- a/templates/cards/list.html +++ b/templates/cards/list.html @@ -9,7 +9,7 @@ {% endif %} {% if page.extra.link %} - Découvrir + {{ section.extra.discover | default(value="Discover") }} {% endif %} {% if not link_after %} diff --git a/templates/index.html b/templates/index.html index ba17e06..457dada 100644 --- a/templates/index.html +++ b/templates/index.html @@ -2,9 +2,14 @@ {% block content -%} +{% set ext = "" -%} +{% if config.default_language != lang -%} +{% set ext = "." ~ lang -%} +{% endif -%} + {% set sections = [] -%} {% for section in config.extra.sections | default(value=[]) -%} -{% set_global sections = sections | concat(with=get_section(path=section ~ "/_index.md")) -%} +{% set_global sections = sections | concat(with=get_section(path=section ~ "/_index" ~ ext ~ ".md")) -%} {% endfor -%}
@@ -12,14 +17,24 @@
+
+ {%- for lang,tr in config.languages %} + {% if config.default_language != lang -%} + {% set url = config.base_url ~ "/" ~ lang -%} + {% endif -%} + {% if not loop.first %}| {% endif -%} + {{ tr.translations.flag | default(value=lang) }} + {%- endfor %} +
+

{{ macro::format_name(name=config.extra.name) }}

- {% if config.extra.roles -%} + {% if section.extra.roles -%}

- {% for role in config.extra.roles -%} + {%- for role in section.extra.roles %} {{ role }}
{% endfor %}