
Revamp the existing translation system, simplifying management and adding several new languages. The new system reads from TOML files in the `/i18n` directory and improves template structures. It also enhances customisation options and robustness by providing fallbacks and modularity. - Implement a new, streamlined translation macro. - Load translations from `/i18n` TOML files. - Remove redundant configuration requirements. - Refactor templates to align with new i18n system. - Add support for Hindi, Japanese, Russian, Portuguese, Chinese, Italian, German, Ukranian, Korean, and French languages. - Credit Thomas Weitzel (@thomasweitzel) for inspiration.
40 lines
1.3 KiB
HTML
40 lines
1.3 KiB
HTML
{% macro format_date(date, short, language_strings="") %}
|
|
|
|
{# Set locale #}
|
|
{% set date_locale = macros_translate::translate(key="date_locale", default="en_GB", language_strings=language_strings) %}
|
|
|
|
{% if config.extra.short_date_format and short %}
|
|
{{ date | date(format=config.extra.short_date_format, locale=date_locale) }}
|
|
{% elif config.extra.long_date_format and not short %}
|
|
{{ date | date(format=config.extra.long_date_format, locale=date_locale) }}
|
|
{% elif not config.extra.short_date_format and date_locale == "en_GB" %}
|
|
{% set day = date | date(format='%-d') | int %}
|
|
|
|
{% if day in [11, 12, 13] %}
|
|
{% set suffix = "th" %}
|
|
{% else %}
|
|
{% set last_digit = day % 10 %}
|
|
{% if last_digit == 1 %}
|
|
{% set suffix = "st" %}
|
|
{% elif last_digit == 2 %}
|
|
{% set suffix = "nd" %}
|
|
{% elif last_digit == 3 %}
|
|
{% set suffix = "rd" %}
|
|
{% else %}
|
|
{% set suffix = "th" %}
|
|
{% endif %}
|
|
{% endif %}
|
|
|
|
{# Return the date. #}
|
|
{{ date | date(format="%-d") }}{{ suffix }}
|
|
{% if short == true %}
|
|
{{ date | date(format="%b %Y") }}
|
|
{% else %}
|
|
{{ date | date(format="%B %Y") }}
|
|
{% endif %}
|
|
{% else %}
|
|
{{ date | date(format="%d %b %Y", locale=date_locale) }}
|
|
{% endif %}
|
|
|
|
{% endmacro %}
|