Date formats are localized and i18n has simple macros

master
southerntofu 2020-03-30 01:14:14 +02:00
parent 56ca660bd7
commit 88dd168707
5 changed files with 27 additions and 18 deletions

View File

@ -29,8 +29,10 @@ source = "Source de cette page"
readmore = "Lire la suite" readmore = "Lire la suite"
previousPage = "Page précédente" previousPage = "Page précédente"
nextPage = "Page suivante" nextPage = "Page suivante"
dateFormat = "%d/%m/%Y"
[translations.en] [translations.en]
source = "Source for this page" source = "Source for this page"
readmore = "Read more" readmore = "Read more"
previousPage = "Previous page" previousPage = "Previous page"
nextPage = "Next page" nextPage = "Next page"
dateFormat = "%m/%d/%Y"

View File

@ -1,5 +1,5 @@
{% import "widgets.html" as widgets %} {% import "widgets.html" as widgets %}
{% set lang = section.lang | default(value=page.lang) %}{% if lang == "en" %}{% set lang = false %}{% endif %} {% set lang = section.lang | default(value=page.lang) %}
<!DOCTYPE html> <!DOCTYPE html>
<html class="no-js" lang="{{ lang | default(value="en")}}"> <html class="no-js" lang="{{ lang | default(value="en")}}">
<head> <head>
@ -14,9 +14,7 @@
<header> <header>
{% set header = get_page(path="_common/header.md") %} {% set header = get_page(path="_common/header.md") %}
{{ header.content | markdown | safe }} {{ header.content | markdown | safe }}
{% if lang %}{{ widgets::menu(content="_common/menu." ~ lang ~ ".md") }} {{ widgets::menu(content="_common/menu.md") }}
{% else %}{{ widgets::menu(content="_common/menu.md") }}
{% endif %}
</header> </header>
<main> <main>
{% block main %} {% block main %}
@ -28,8 +26,7 @@
<footer> <footer>
{% if config.extra.forge %} {% if config.extra.forge %}
<aside class="source"> <aside class="source">
{% if lang %}{% set translated = trans(key="source", lang=lang) %} {% set translated = widgets::i18n(key="source") %}
{% else %}{% set translated = trans(key="source") %}{% endif %}
{% if section %} {% if section %}
<a href="{{ config.extra.forge.browse }}content/{{ section.path }}_index.md">{{ translated }}</a> <a href="{{ config.extra.forge.browse }}content/{{ section.path }}_index.md">{{ translated }}</a>
{% else %} {% else %}

View File

@ -7,7 +7,7 @@
<div> <div>
<h1 class="p-name">{{ page.title }}</h1> <h1 class="p-name">{{ page.title }}</h1>
<a class="u-url" hidden aria-hidden="true" href="{{ page.permalink }}">Permalink</a> <a class="u-url" hidden aria-hidden="true" href="{{ page.permalink }}">Permalink</a>
{%- if page.date -%}<time class="dt-published" datetime="{{ page.date }}">📅&nbsp;{{ page.date | date(format="%d/%m/%Y") }}</time>{%- endif -%} {%- if page.date -%}<time class="dt-published" datetime="{{ page.date }}">📅&nbsp;{{ page.date | date(format=widgets::i18n(key="dateFormat")) }}</time>{%- endif -%}
</div> </div>
<div class="e-content">{{ page.content | safe }}</div> <div class="e-content">{{ page.content | safe }}</div>
</article> </article>

View File

@ -11,12 +11,12 @@
<article> <article>
<div> <div>
<a class="u-url" href="{{ page.permalink }}"><h2>{{ page.title }}</h2></a> <a class="u-url" href="{{ page.permalink }}"><h2>{{ page.title }}</h2></a>
{%- if page.date -%}<time class="dt-published" datetime="{{ page.date }}">📅&nbsp;{{ page.date | date(format="%d/%m/%Y") }}</time>{%- endif -%} {%- if page.date -%}<time class="dt-published" datetime="{{ page.date }}">📅&nbsp;{{ page.date | date(format=widgets::i18n(key="dateFormat")) }}</time>{%- endif -%}
</div> </div>
{% if page.summary %} {% if page.summary %}
<div class="p-summary e-content"> <div class="p-summary e-content">
{{ page.summary | markdown | safe }} {{ page.summary | markdown | safe }}
<a class="read-more" href="{{ page.permalink }}">--> {% if lang %}{{ trans(key="readmore", lang=lang) }}{% else %}{{ trans(key="readmore") }}{% endif %} <--</a> <a class="read-more" href="{{ page.permalink }}">--> {{ widgets::i18n(key="readmore") }} <--</a>
</div> </div>
{% else %} {% else %}
<div class="e-content"> <div class="e-content">
@ -28,16 +28,10 @@
{% if paginator and paginator.number_pagers > 1 %} {% if paginator and paginator.number_pagers > 1 %}
<aside class="pagination"> <aside class="pagination">
{% if paginator.previous %} {% if paginator.previous %}
<a href="{{ paginator.previous }}"> <a href="{{ paginator.previous }}"><--&nbsp;&nbsp;{{ widgets::i18n(key="previousPage") }}</a>
<--&nbsp;&nbsp;{% if lang %}{{ trans(key="previousPage", lang=lang) }}
{% else %}{{ trans(key="previousPage") }}{% endif %}
</a>
{% endif %} {% endif %}
{% if paginator.next %} {% if paginator.next %}
<a href="{{ paginator.next }}"> <a href="{{ paginator.next }}">{{ widgets::i18n(key="nextPage") }}&nbsp;&nbsp;--></a>
{% if lang %}{{ trans(key="nextPage", lang=lang) }}
{% else %}{{ trans(key="nextPage") }}{% endif %}&nbsp;&nbsp;-->
</a>
{% endif %} {% endif %}
</aside> </aside>
{% endif %} {% endif %}

View File

@ -17,9 +17,25 @@ a submenu. A submenu is an actual list
######################################} ######################################}
{% macro menu(content) %} {% macro menu(content) %}
<nav class="nav-menu" role="navigation"> <nav class="nav-menu" role="navigation">
{%- set source = get_page(path=content) %}{% set entries = source.content | split(pat="<hr />") %}{# fetch page content and divide it with separator -#} {%- set source = get_page(path=self::i18n_page(page=content)) %}{% set entries = source.content | split(pat="<hr />") %}{# fetch page content and divide it with separator -#}
{%- for entry in entries %} {%- for entry in entries %}
{{ entry | trim | replace(from="<p>", to="") | replace(from="</p>", to="") | safe }}{# strip paragraph tags away for nicer markup #} {{ entry | trim | replace(from="<p>", to="") | replace(from="</p>", to="") | safe }}{# strip paragraph tags away for nicer markup #}
{%- endfor %} {%- endfor %}
</nav> </nav>
{% endmacro menu %} {% endmacro menu %}
{%- macro i18n(key) -%}
{{ trans(key=key, lang=lang) }}
{%- endmacro i18n -%}
{%- macro i18n_page(page) -%}
{% if lang == "en" %}{{ page }}
{%- else -%}
{%- set parts = page | split(pat=".md") -%}
{%- for part in parts -%}
{%- if part and not loop.first -%}.md{%- endif -%}
{%- if not loop.last -%}{{ part }}{%- endif -%}
{%- endfor -%}
.{{ lang }}.md
{%- endif -%}
{%- endmacro i18n_page -%}