Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme translations #2396

Open
clarfonthey opened this issue Dec 30, 2023 · 3 comments
Open

Theme translations #2396

clarfonthey opened this issue Dec 30, 2023 · 3 comments

Comments

@clarfonthey
Copy link
Contributor

Documentation issue

Summary

While it's clear that the translation system will be reworked eventually (#1058), right now a problem that exists is the fact that themes can't easily be translated. For example, if a theme includes custom translations that it wants to use via the trans template, these have to be included by the parent config.toml and can't be included directly as part of the theme.

Proposed solution

For now, probably the easiest method would be to simply copy the translations and languages.*.translations keys from theme.toml into the existing theme configs so that they can be combined with the config.toml keys.

@welpo
Copy link
Contributor

welpo commented Jan 5, 2024

if a theme includes custom translations that it wants to use via the trans template, these have to be included by the parent config.toml and can't be included directly as part of the theme

While this is true if you want to use the trans template, there are ways to translate a theme. See how the Zolarwind theme does it.

I implemented a more complex version of this for tabi: see the PR and the docs for end-users.

In short:

  1. Load the data:
{# Load the internationalisation data for the current language from
the .toml files in the user's '/i18n' folder, falling back to the theme's.
This variable will hold all the text strings for the language #}
{%- set language_strings = load_data(path="i18n/" ~ lang ~ '.toml', required=false) -%}
{%- if not language_strings -%}
    {%- set language_strings = load_data(path="themes/tabi/i18n/" ~ lang ~ ".toml", required=false) -%}
{%- endif -%}
  1. Set up a macro:
{% macro translate(key, language_strings="", default="") %}
{{- language_strings[key] | default(value=default) | safe -}}
{% endmacro %}
  1. Translate:
{{- macros_translate::translate(key="visit_the_site", default="Visit website", language_strings=language_strings) -}}

@clarfonthey
Copy link
Contributor Author

I mean, that's fair: you could do it manually, but it's still suboptimal that zola offers its own translation system and themes can't leverage that at all. Plus, eventually zola will have Fluent support, which will make it even more important to expose this to themes.

@Keats
Copy link
Collaborator

Keats commented Jan 7, 2024

I don't really want to add more with the basic translation system since it's meant to be replaced. Although at the same time it seems fluent is going to be superseded by something else (MF2)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants