feat(copyright): Manage translations in config

As copyright is part of config, it is easier to manage its translations
at the same place.
`config.extra.translate_copyright` is still used to declare translation
intent for backward compatibility.
It allows to raise an error at build time if someone forgot to move from
using i18n files as previously required to the config.toml.
This commit is contained in:
ZzMzaw 2023-10-26 22:34:00 +02:00
parent ebaf1588a7
commit 1c6834a44e
6 changed files with 30 additions and 8 deletions

View file

@ -194,8 +194,12 @@ footer_menu = [
# copyright = "© $CURRENT_YEAR Your Name $SEPARATOR Unless otherwise noted, the content in this website is available under the [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/) license."
# For multi-language sites, you can set a different copyright for each language.
# If this is set to true, ensure you have a `copyright` translation for each language.
# If this is set to true, ensure you have a translation in `copyright_translations` for each language.
translate_copyright = false
# If `translate_copyright` is set to true, `copyright_translations` can be empty but must exist.
# A build time error will be raised otherwise in order to make sure people already using previous translation method (i18n files) won't forgot to move translations back in config.toml.
# If a translation is missing for language, the `copyright` value will be used instead.
# copyright_translations.es = "© $CURRENT_YEAR Your Name $SEPARATOR A menos que se indique lo contrario, el contenido de este sitio web está disponible bajo la licencia [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)."
# Custom security headers. What urls should your website be able to connect to?
# You need to specify the CSP and the URLs associated with the directive.

View file

@ -554,7 +554,11 @@ copyright = "© $CURRENT_YEAR Your Name $SEPARATOR Unless otherwise noted, the c
Si tens un lloc multilingüe i vols establir diferents notificacions de drets d'autor per a diferents idiomes, pots:
1. Configura `translate_copyright = true` a `config.toml`.
2. Afegeix una clau `copyright` als arxius `i18n`. Consulta la [documentació](/ca/blog/faq-languages/#com-puc-personalitzar-o-sobreescriure-una-cadena-de-text-específica-al-meu-lloc-web).
2. Afegeix una traducció a `copyright_translations` per a l'idioma esperat (que coincideix amb la variable `lang`) de la manera següent:
```toml
copyright_translations.es = "© $CURRENT_YEAR Your Name $SEPARATOR A menos que se indique lo contrario, el contenido de este sitio web está disponible bajo la licencia [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)."
```
---

View file

@ -552,7 +552,11 @@ copyright = "© $CURRENT_YEAR Your Name $SEPARATOR Unless otherwise noted, the c
Si tienes un sitio multilingüe y deseas establecer diferentes notificaciones de derechos de autor para diferentes idiomas, puedes:
1. Configura `translate_copyright = true` en `config.toml`.
2. Añade una clave `copyright` a los archivos `i18n`. Consulta la [documentación](/es/blog/faq-languages/#cómo-personalizo-o-sobrescribo-una-cadena-de-texto-específica-en-mi-sitio-web).
2. Añade una traducción en `copyright_translations` para el idioma esperado (que coincida con la variable `lang`) de la siguiente manera:
```toml
copyright_translations.es = "© $CURRENT_YEAR Your Name $SEPARATOR A menos que se indique lo contrario, el contenido de este sitio web está disponible bajo la licencia [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)."
```
---

View file

@ -556,7 +556,11 @@ copyright = "© $CURRENT_YEAR Your Name $SEPARATOR Unless otherwise noted, the c
If you have a multilingual site and want to set different copyright notices for different languages, you can:
1. Set `translate_copyright = true` in `config.toml`.
2. Add a `copyright` key to the `i18n` files. See the [documentation](/blog/faq-languages/#how-do-i-customise-or-override-a-specific-text-string-on-my-website).
2. Add a translation to `copyright_translations` for the expected language (matching the `lang` variable) as follow:
```toml
copyright_translations.es = "© $CURRENT_YEAR Your Name $SEPARATOR A menos que se indique lo contrario, el contenido de este sitio web está disponible bajo la licencia [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)."
```
---

View file

@ -89,12 +89,14 @@
{# Shows optional Copyright notice #}
{%- if config.extra.copyright -%}
{% set current_year = now() | date(format="%Y") %}
{% set copyright = config.extra.copyright %}
{# Translate the copyright if set in the config #}
{%- if config.extra.translate_copyright -%}
<p>{{ macros_translate::translate(key="copyright", default=config.extra.copyright, language_strings=language_strings) | replace(from="$CURRENT_YEAR", to=current_year) | replace(from="$SEPARATOR", to=separator) | markdown | safe }}</p>
{%- else -%}
<p>{{ config.extra.copyright | replace(from="$CURRENT_YEAR", to=current_year) | replace(from="$SEPARATOR", to=separator) | markdown | safe }}</p>
{%- if lang in config.extra.copyright_translations -%}
{% set copyright = config.extra.copyright_translations[lang] %}
{%- endif -%}
{%- endif -%}
<p>{{ copyright | replace(from="$CURRENT_YEAR", to=current_year) | replace(from="$SEPARATOR", to=separator) | markdown | safe }}</p>
{%- endif -%}
{# Shows "Powered by Zola & tabi" notice #}

View file

@ -173,8 +173,12 @@ encode_plaintext_email = true # Setting is ignored if email is already encoded.
# copyright = "© $CURRENT_YEAR Your Name $SEPARATOR Unless otherwise noted, the content in this website is available under the [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/) license."
# For multi-language sites, you can set a different copyright for each language.
# If this is set to true, ensure you have a `copyright` translation for each language.
# If this is set to true, ensure you have a translation in `copyright_translations` for each language.
translate_copyright = false
# If `translate_copyright` is set to true, `copyright_translations` can be empty but must exist.
# A build time error will be raised otherwise in order to make sure people already using previous translation method (i18n files) won't forgot to move translations back in config.toml.
# If a translation is missing for language, the `copyright` value will be used instead.
# copyright_translations.es = "© $CURRENT_YEAR Your Name $SEPARATOR A menos que se indique lo contrario, el contenido de este sitio web está disponible bajo la licencia [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)."
# Custom security headers. What urls should your website be able to connect to?
# You need to specify the CSP and the URLs associated with the directive.