🌐 feat(i18n): overhaul translation system & add languages (#145)
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.
1 year ago
|
|
|
<li class="language-switcher">
|
|
|
|
<details class="dropdown">
|
|
|
|
<summary role="button" aria-haspopup="true" title="{{ macros_translate::translate(key="language_selection", default="Language selection", language_strings=language_strings) }}" aria-label="{{ macros_translate::translate(key="language_selection", default="Language selection", language_strings=language_strings) }}">
|
|
|
|
<div class="language-switcher-icon"></div>
|
|
|
|
</summary>
|
|
|
|
<div class="dropdown-content" role="menu">
|
🌐 feat(i18n): overhaul translation system & add languages (#145)
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.
1 year ago
|
|
|
{#- Display the current language first in the dropdown -#}
|
|
|
|
{{ macros_translate::translate(key="language_name", default=lang, language_strings=language_strings) }}
|
|
|
|
{#- Loop through all the available languages in the config -#}
|
|
|
|
{%- for lcode, ldetails in config.languages -%}
|
|
|
|
{#- Skip the current language to avoid linking to the current page -#}
|
|
|
|
{%- if lang == lcode -%}
|
|
|
|
{%- continue -%}
|
|
|
|
{%- endif -%}
|
|
|
|
{#- Dynamically load the language strings for each language -#}
|
|
|
|
{%- set other_language_strings = load_data(path="i18n/" ~ lcode ~ ".toml", required=false) -%}
|
|
|
|
{%- if not other_language_strings -%}
|
|
|
|
{%- set other_language_strings = load_data(path="themes/tabi/i18n/" ~ lcode ~ ".toml", required=false) -%}
|
|
|
|
{%- endif -%}
|
|
|
|
{#- Use the loaded language strings to get the language name -#}
|
|
|
|
{% set language_name = macros_translate::translate(key="language_name", default=lcode,
|
|
|
|
language_strings=other_language_strings) %}
|
|
|
|
{#- Check if the language code matches the default language -#}
|
|
|
|
{%- if lcode == config.default_language -%}
|
|
|
|
{#- If it does, link to the root path (no language code in URL) -#}
|
|
|
|
<a role="menuitem" lang="{{ lcode }}" aria-label="{{ language_name }}" href="{{ current_url | replace(from='/' ~ lang ~ '/', to = '/') }}">{{ language_name }}</a>
|
🌐 feat(i18n): overhaul translation system & add languages (#145)
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.
1 year ago
|
|
|
{#- Check if the current language is the default language -#}
|
|
|
|
{#- If it is, append the language code to the base URL -#}
|
|
|
|
{%- elif lang == config.default_language -%}
|
|
|
|
<a role="menuitem" lang="{{ lcode }}" aria-label="{{ language_name }}" href="{{ config.base_url }}/{{ lcode }}{{ current_path | default(value="/") | safe }}">{{ language_name }}</a>
|
🌐 feat(i18n): overhaul translation system & add languages (#145)
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.
1 year ago
|
|
|
{%- else -%}
|
|
|
|
{#- If it's not, replace the current language code in the URL with the new one -#}
|
|
|
|
<a role="menuitem" lang="{{ lcode }}" aria-label="{{ language_name }}" href="{{ current_url | replace(from='/' ~ lang ~ '/', to='/' ~ lcode ~ '/') }}">{{ language_name }}</a>
|
🌐 feat(i18n): overhaul translation system & add languages (#145)
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.
1 year ago
|
|
|
{%- endif -%}
|
|
|
|
{%- endfor -%}
|
|
|
|
</div>
|
|
|
|
</details>
|
🌐 feat(i18n): overhaul translation system & add languages (#145)
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.
1 year ago
|
|
|
</li>
|
|
|
|
|
|
|
|
<ul class="language-switcher">
|
|
|
|
{% for trans in page.translations %}
|
|
|
|
<li>
|
|
|
|
<a href="{{ trans.permalink }}" lang="{{ trans.lang }}">
|
|
|
|
{{ config.extra.languages[trans.lang] | default(value=trans.lang) }}
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
{% endfor %}
|
|
|
|
</ul>
|