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

Add localization support 1 #226

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

hydra
Copy link
Contributor

@hydra hydra commented Nov 28, 2024

Current state: work-in-progress.

TODO:

  • API documentation.
  • Additional testing.
  • PR review and changes.

Initial cut of localization support using Fluent.

See examples/localized.rs.

Features:

  • When translations are missing, the key is displayed.
  • The first translation specified becomes the default when the system local doesn't match.
  • Widgets can be wrapped in Localized to allow for multiple translations to be used at the same time. Use-case is a form designer or report viewer where the main application is in one-language, but you want to preview a form or report in a different language. It works in the same way to being able to override the theme for a widget.
  • Supports dynamic translation arguments.

Screenshots:

image

In this screenshot, the window uses the default locale, and the first container shows a label using the window's default locale.
The second container shows a label using a specific locale. The third container is using uses a dynamic locale which can be changed using the radio buttons. It has buttons which update a dynamic value which is used as an argument for a translation.

image

In this screenshot, the language was changed to "Spanish (Spain)" and the "+" button was clicked once. Here we can see the translations were used.

Fluent translation file for 'es-ES' in the screenshots above is as follows:

message-hello-world = ¡Hola, mundo!
language-en-gb = Inglés (Gran Bretaña)
language-en-us = Inglés (Estados Unidos)
language-es-es = Español (España)
banana-counter-message =
    { $bananas_counter ->
        [one] Hay un plátano.
        *[other] Tienes { $bananas_counter } plátanos.
    }

image

In this screenshot, we can see what the UI looks like when no translations are provided.

Limitations:

  • Translations are currently re-parsed for each opened window. Some translations cache could be used in the future.
  • Window titles do not currently support localization.

Acknowledgements:

Copy link
Member

@ecton ecton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes should hopefully fix the layout invalidation issues reported on Discord.

src/localization.rs Outdated Show resolved Hide resolved
src/context.rs Outdated Show resolved Hide resolved
src/context.rs Outdated Show resolved Hide resolved
src/context.rs Outdated Show resolved Hide resolved
hydra added a commit to hydra/cushy that referenced this pull request Nov 28, 2024
hydra added a commit to hydra/cushy that referenced this pull request Nov 28, 2024
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

Successfully merging this pull request may close these issues.

2 participants