-
Notifications
You must be signed in to change notification settings - Fork 9
Add support for translations from .po and .mo files using rspolib
#28
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
Conversation
The rspolib feature adds `RSPoLibTranslator` and re-exports `rspolib`. The plural rules parser was originally written by Olivier Goffart <olivier.goffart@slint.dev>.
|
As a side note: I had to do the edition upgrade for compilation, but I haven't done any other "upgrades". I'd be happy to do those, for example explicit features and using |
ogoffart
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From an API point of view, I wonder if this should belong in a rspolib_01 module.
So we'd do:
tr::set_translator!(tr::rspolib_01::RSPoLibTranslator::try_from(
tr::rspolib_01::rspolib::pofile("....po").unwrap()
).unwrap()));But I get that this is a bit long to use tr::rspolib_01::rspolib
But the point is trying to keep it separate.
Another idea would be to hide the rspolib API entirely, and have an API like so:
fn load_po_file(path: Path) -> impl Translator
fn po_data(data: &[u8]) -> impl Translator
fn load_mo_file(path: Path) -> impl Translator
fn mo_data(data: &[u8]) -> impl TranslatorCo-authored-by: Olivier Goffart <olivier.goffart@slint.dev>
Instead, have mo-translator and po-translator features, that activate each opaque MoTranslator and PoTranslator types, which can be constructed from paths or vecs.
| categories = ["internationalization", "localization"] | ||
| edition = "2018" | ||
| edition = "2021" | ||
| rust-version = "1.81" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the MSRV so high?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the last failed build attempt in the CI:
error: package `half v2.6.0` cannot be built because it requires rustc 1.81 or newer, while the currently active rustc version is 1.74.1
|
I'm wondering how to do the dynamic language change. We would have to call set_translator but that takes ownership. Meaning we need to always reload the file. Perhaps the trick here is to implement the Translator trait for Arc |
|
are you concerned that switching say between de, fr, and back to de, the de mo file is parsed twice? I agree that Arc would fix it, but it's an interesting tradeoff to make (memory vs performance over a rare operation). |
The rspolib feature adds
RSPoLibTranslatorand re-exportsrspolib.The plural rules parser was originally written by Olivier Goffart olivier.goffart@slint.dev.