feat(copyright): set copyright translations outside toml files & enhance $VARs (#215)

Co-authored-by: welpo <welpo@users.noreply.github.com>
main
ZzMzaw 1 year ago committed by GitHub
parent 46e0681193
commit b6fa54c556
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -189,14 +189,17 @@ footer_menu = [
]
# Enable a copyright notice for the footer, shown between socials and the "Powered by" text.
# You can use $CURRENT_YEAR to automatically insert the current year.
# $TITLE will be replaced by the website's title.
# $CURRENT_YEAR will be replaced by the current year.
# $AUTHOR will be replaced by the `author` variable.
# $SEPARATOR will be replaced by the `separator` variable.
# Markdown is supported (links, emphasis, etc).
# 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."
# copyright = "$TITLE © $CURRENT_YEAR $AUTHOR $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.
translate_copyright = false
# The old way of setting `translated_copyright = true` and using i18n files is deprecated.
# If a translation is missing for language, the `copyright` value will be used.
# copyright_translations.es = "$TITLE © $CURRENT_YEAR $AUTHOR $SEPARATOR A menos que se indique lo contrario, el contenido de esta 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.

@ -550,14 +550,20 @@ Per afegir una menció sobre els drets d'autor al teu lloc web, configura `copyr
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."
```
`$CURRENT_YEAR` es substituirà per l'any actual i `$SEPARATOR` es substituirà per la [variable `separator`](#separador-personalitzat). El text es processarà en Markdown. Per exemple:
- `$TITLE` serà reemplaçat per la variable `title` configurada a `config.toml`
- `$CURRENT_YEAR` serà reemplaçat per l'any actual
- `$AUTHOR` serà reemplaçat per la variable `author`
- `$SEPARATOR` serà reemplaçat per la [variable `separator`](#separador-personalitzat).
El text es processarà en Markdown. Per exemple, la configuració d'adalt:
{{ dual_theme_image(light_src="blog/mastering-tabi-settings/img/copyright_light.webp", dark_src="blog/mastering-tabi-settings/img/copyright_dark.webp" alt="Secció de drets d'autor", full_width=true) }}
Si tens un lloc multilingüe i vols establir diferents notificacions de drets d'autor per a diferents idiomes, pots:
Si tens un lloc multilingüe i vols establir diferents notificacions de drets d'autor per a diferents idiomes, afegeix la traducció corresponent a `copyright_translations.{codi_d'idioma}` per a cada idioma que vulguis donar suport. El codi de llengua ha de coincidir amb el [codi de llengua de tabi](https://welpo.github.io/tabi/ca/blog/faq-languages/#que-son-aquests-codis-de-dues-lletres). Per exemple, pel castellà:
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).
```toml
copyright_translations.es = "© $CURRENT_YEAR $AUTHOR $SEPARATOR A menos que se indique lo contrario, el contenido de esta web está disponible bajo la licencia [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)."
```
---

@ -548,14 +548,20 @@ Para añadir una mención sobre los derechos de autor a tu sitio web, configura
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."
```
`$CURRENT_YEAR` se reemplazará por el año actual y `$SEPARATOR` se reemplazará por la [variable `separator`](#separador-personalizado). Se procesará el texto en Markdown. Por ejemplo:
- `$TITLE` será reemplazado por la variable `title` configurada en `config.toml`
- `$CURRENT_YEAR` será reemplazado por el año actual
- `$AUTHOR` será reemplazado por la variable `author`
- `$SEPARATOR` será reemplazado por la [variable `separator`](#separador-personalizado).
Se procesará el texto en Markdown. Por ejemplo, la configuració de arriba:
{{ dual_theme_image(light_src="blog/mastering-tabi-settings/img/copyright_light.webp", dark_src="blog/mastering-tabi-settings/img/copyright_dark.webp" alt="Sección de derechos de autor", full_width=true) }}
Si tienes un sitio multilingüe y deseas establecer diferentes notificaciones de derechos de autor para diferentes idiomas, puedes:
Si tienes un sitio multilingüe y deseas establecer diferentes notificaciones de derechos de autor para diferentes idiomas, añade la traducción correspondiente a `copyright_translations.{código_de_idioma}` para cada idioma que quieras dar soporte. El código de idioma debe coincidir con el [código de idioma de tabi](https://welpo.github.io/tabi/es/blog/faq-languages/#que-son-estos-codigos-de-dos-letras). Por ejemplo:
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).
```toml
copyright_translations.es = "© $CURRENT_YEAR $AUTHOR $SEPARATOR A menos que se indique lo contrario, el contenido de esta web está disponible bajo la licencia [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)."
```
---

@ -552,14 +552,22 @@ To add a copyright notice to your site, set `copyright`:
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."
```
`$CURRENT_YEAR` will be replaced by the current year, and `$SEPARATOR` will be replaced by the [`separator` variable](#custom-separator). Markdown is rendered. The example above:
You can use the following variables:
- `$TITLE` will be replaced by `title` variable set in `config.toml`
- `$CURRENT_YEAR` will be replaced by the current year
- `$AUTHOR` will be replaced by the `author` variable
- `$SEPARATOR` will be replaced by the [`separator` variable](#custom-separator)
Markdown is rendered. The example above:
{{ dual_theme_image(light_src="blog/mastering-tabi-settings/img/copyright_light.webp", dark_src="blog/mastering-tabi-settings/img/copyright_dark.webp" alt="Copyright section", full_width=true) }}
If you have a multilingual site and want to set different copyright notices for different languages, you can:
If you have a multilingual site and want to set different copyright notices for different languages, you can add the corresponding translation to `copyright_translations.{language_code}` for each language you want to support. The language code must match [tabi's language code](https://welpo.github.io/tabi/blog/faq-languages/#what-are-these-two-letter-codes). For example, for Spanish:
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).
```toml
copyright_translations.es = "© $CURRENT_YEAR $AUTHOR $SEPARATOR A menos que se indique lo contrario, el contenido de esta web está disponible bajo la licencia [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)."
```
---

@ -0,0 +1,41 @@
{%- if config.extra.copyright -%}
{% set copyright = config.extra.copyright %}
{# Try to look for a language-specific copyright notice in the new config setup #}
{%- if config.extra.copyright_translations -%}
{%- if lang in config.extra.copyright_translations -%}
{% set copyright = config.extra.copyright_translations[lang] %}
{%- endif -%}
{%- elif config.extra.translate_copyright -%}
{# Old way to translate the copyright through toml files #}
{# When the feature is removed, uncomment below to throw a descriptive error #}
{# {{ throw(message="ERROR: The 'translate_copyright' feature has been deprecated. Please set 'copyright_translations' in config.toml. See the documentation: https://welpo.github.io/tabi/blog/mastering-tabi-settings/#copyright") }} #}
{% set copyright = macros_translate::translate(key="copyright", default=config.extra.copyright, language_strings=language_strings) %}
{%- endif -%}
{# Check for missing variables in the notice #}
{% set copyright_placeholders = ["$AUTHOR", "$TITLE"] %}
{% set missing_vars = [] %}
{% for placeholder in copyright_placeholders %}
{% if placeholder in copyright %}
{# Attempt to retrieve the corresponding variable by trimming the $ sign and converting to lowercase #}
{% set var_name = placeholder | replace(from="$", to="") | lower %}
{% if not config[var_name] %}
{# Append the variable name to the list of missing variables #}
{% set_global missing_vars = missing_vars | concat(with=var_name) %}
{% endif %}
{% endif %}
{% endfor %}
{% if missing_vars | length > 0 %}
{% set missing_vars_str = missing_vars | join(sep=", ") %}
{{ throw(message="ERROR: The following variables are included in `copyright` but have not been set in the config.toml: " ~ missing_vars_str) }}
{% endif %}
{# At this point, we know that all variables needed defined, so we can safely override the missing ones #}
{% set author = config.author | default(value="") %}
{% set title = config.title | default(value="") %}
{# Render the copyright notice, replacing the variables #}
{% set current_year = now() | date(format="%Y") %}
<p>{{ copyright | replace(from="$AUTHOR", to=author) | replace(from="$TITLE", to=title) | replace(from="$CURRENT_YEAR", to=current_year) | replace(from="$SEPARATOR", to=separator) | markdown | safe }}</p>
{%- endif -%}

@ -92,16 +92,7 @@
<div class="credits">
<small>
{# Shows optional Copyright notice #}
{%- if config.extra.copyright -%}
{% set current_year = now() | date(format="%Y") %}
{# 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>
{%- endif -%}
{%- endif -%}
{% include "partials/copyright.html" %}
{# Shows "Powered by Zola & tabi" notice #}
{{ macros_translate::translate(key="powered_by", default="Powered by", language_strings=language_strings) }}

@ -168,14 +168,17 @@ encode_plaintext_email = true # Setting is ignored if email is already encoded.
# ]
# Enable a copyright notice for the footer, shown between socials and the "Powered by" text.
# You can use $CURRENT_YEAR to automatically insert the current year.
# $TITLE will be replaced by the website's title.
# $CURRENT_YEAR will be replaced by the current year.
# $AUTHOR will be replaced by the `author` variable.
# $SEPARATOR will be replaced by the `separator` variable.
# Markdown is supported (links, emphasis, etc).
# 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."
# copyright = "$TITLE © $CURRENT_YEAR $AUTHOR $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.
translate_copyright = false
# The old way of setting `translated_copyright = true` and using i18n files is deprecated.
# If a translation is missing for language, the `copyright` value will be used.
# copyright_translations.es = "$TITLE © $CURRENT_YEAR $AUTHOR $SEPARATOR A menos que se indique lo contrario, el contenido de esta 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.

Loading…
Cancel
Save