-
Notifications
You must be signed in to change notification settings - Fork 666
Add support for translations without gettext #3715
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
Comments
I know that this has been discussed before and that the idea was already discarded, but isn't it worthwhile, however, to give users the option of using fluent-rs instead of gettext, since it works very well under any system, including windows. This way, the external dependence on the code in C can be removed and it will make cross-compilation easier. |
Regarding fluent, this can be done by using a global. |
Any progress on changing the language dynamically? |
Changing translations dynamically (when using gettext) is implemented in the master branch. This ticket was split and slightly confusing, so I've refocused it on the gettext removal. |
I'm proposing to have the following:
The the compiler would look at the content of and look for file with a given pattern.
We can use crates like private_api::format_string(match private_api::language() {
1 => "Bonjour {}",
2 => "Hallo {}",
_ => "Hello {}",
},&[name]); Or maybe private_api::translation(&["Hello {}", "Bonjour {}", "Hallo {}"], &[name]) We can even have warning if a string or translated string don't have the right format, (or doesn't exist ?) Now we still need a way to set or change the language. This solution also doesn't help to translate strings in the native C++/Rust code. This is mostly useful for MCU or platform without file system. |
I agree that this is the way to go, roughly. In terms of language selection: I think the build system API should explicitly say which languages/translations to pick. This permits creating multi-language builds as well as region-specific builds. Later the list of support translations could also go into the project file, to enable access in the live-preview. Generally, I think it makes sense to see translations like resources/assets and bundle them, also on targets with operating systems, as opt-in. |
I'm currently struggling with setting up translations for the new LibrePCB UI and I think a generic translators API as suggested in the initial post would be very helpful. My situation:
For the C++ backend I want to keep the current system - it would be way too much effort to change it, and actually Qt provides a mature translations toolkit which works very well and flawlessly across all platforms. For the Slint UI there are two solutions provided:
In either way, in the end I prefer to use the same system for both the UI and the backend, to keep a common workflow, consistent behavior, and low maintenance effort. So I wonder if I could use Qt's mature and painless translation system for the Slint UI? One option would be to use a custom callback (implemented in the backend) instead of So I wonder if I could use One tricky thing however would be placeholders handling. Slint uses Would such a custom Any tip would be much appreciated. |
I just saw So it's not really a surprise that this crate causes troubles on Windows :-/ Now I investigated a bit the approach of a translate callback. It looks like this call from |
We need to support user changing translations through the interface, as well as translation on platform that do not have gettext (MCU)
The idea would be somehow to have API to provide a translator.
Perhaps we can re-use an interface similar to https://docs.rs/tr/latest/tr/trait.Translator.html
and have a global setter to set it. That setter would mark all translated string as dirty.
( This should also help for #3307 )
The text was updated successfully, but these errors were encountered: