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

🌐 feat(i18n): overhaul translation system & add languages #145

Merged
merged 1 commit into from
Sep 12, 2023

Conversation

welpo
Copy link
Owner

@welpo welpo commented Sep 12, 2023

TL;DR Overhauled the translation system, loading strings from /i18n TOML files.

Overview

This PR aims to significantly improve the localisation system, streamline template structures, and add multiple new languages. It offers a more user-friendly approach to managing translations and addresses several issues related to the readability and maintainability of the codebase.

Advantages

  1. Ease of Translation Management: Moved translations to an /i18n folder, allowing easier addition and modification.

  2. User customisation: Theme users can easily override or add new translation strings without touching the core logic.

  3. Flexible default language: Users can set a default language other than English.

  4. Robustness: Missing translation strings will fall back to English, reducing the chance of errors.

  5. Reduced configuration: Eliminated the need for config.extra.languages and copying/pasting strings into config files.

  6. Modularity: Enhanced modularity by isolating translation and language-switching logic.

  7. Simplicity: Simplified the translation macro, making it easier to read and maintain.

  8. Performance: Potentially minor performance gains by reducing conditional checks.

Also fixes #134.


Changes

  1. New translation system:
  • Replaced the old translation macro with a more streamlined version that's easier to maintain and extend.
  • Translation strings are now loaded from TOML files within the /i18n directory, allowing for easy management.
  1. Updated macro calls:
  • All existing macro calls have been updated to utilise the new language_strings variable, aligning them with the improved translation system. All translated strings are now optional, falling back to English.
  1. Template refactoring:
  1. UI improvements:
  • Fixed a minor spacing issue in the multilingual quotes shortcode.
  1. Languages added:
  • Chinese (Simplified) (machine translation)
  • French (machine translation)
  • Hindi (machine translation)
  • Italian (machine translation)
  • Japanese (machine translation)
  • Korean (machine translation)
  • Portuguese (European) (reviewed by native speaker)
  • Russian (reviewed by native speaker)
  • Ukranian (machine translation)

Credit

This overhaul was inspired by Thomas Weitzel's (@thomasweitzel) work on the i18n of his Zolarwind theme.

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.
@welpo welpo added bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request labels Sep 12, 2023
@welpo welpo merged commit 32a2d50 into main Sep 12, 2023
1 check passed
@welpo welpo deleted the feat/overhaul-i18n branch September 12, 2023 16:58
@Jieiku
Copy link
Contributor

Jieiku commented Sep 12, 2023

Oh my "All translated strings are now optional, falling back to English."

That alone is absolutely worth pursuing this! I will be following up with doing the same!

@welpo
Copy link
Owner Author

welpo commented Sep 12, 2023

Finally found a way to do it!

@Jieiku
Copy link
Contributor

Jieiku commented Sep 12, 2023

Regarding the "machine translation" did you find a convenient way to automatically pull the translations into files? or was it copy paste into google translate. (which is how I did most of mine)

@welpo
Copy link
Owner Author

welpo commented Sep 12, 2023

I asked GPT-4 for the translations, giving it the en.toml file, some context, and my requirements.

I validated the output (like the joined 404 keys, or the metadata in context) to make minor adjustments (with GPT-4), and finally I translated the keys on Google Translate and/or DeepL to verify it was reasonable.

@Jieiku
Copy link
Contributor

Jieiku commented Sep 12, 2023

I just tested using this: https://github.com/mgruner/deepl-api-rs
docs: https://mgruner.github.io/deepl-api-rs-docs/deepl/index.html

I signed up for the free account, and it seems to work:

echo "Recent Posts" | deepl translate --source-language EN --target-language FR | cat -

Messages récents

There is a 500,000 monthly character limit, so no idea how quickly I would hit that limit.

For a small site I would think your unlikely to hit the limit very fast. After I implement what you have done here, I would like to try automating some of the translations, possibly via a bash script.

I am going to see if there is a way to automate the use of GPT-4 as well, no idea if they have an API yet.

@welpo welpo added the i18n Internationalisation label Sep 18, 2023
Jieiku referenced this pull request in Jieiku/abridge Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request i18n Internationalisation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing title on /tags
2 participants