kellpossible / cargo-i18n

A Rust Cargo sub-command and libraries to extract and build localization resources to embed in your application/library
MIT License
120 stars 24 forks source link

Mixed locale support? #114

Open VorpalBlade opened 7 months ago

VorpalBlade commented 7 months ago

Sorry if this is documented somewhere but I couldn't find it. How does mixed locale support work in this library? E.g. If I set LC_MESSAGES and LC_NUMERIC to different values?

I'm considering using this for a command line program of mine and proper mixed locale support is something I consider absolutely critical. I use it myself (I prefer English text due to poor translations, and poor searchability of translated errors. But I want Monday as first day of week, comma as the decimal separator, Swedish weekday names, 24h time, sane date format etc).

But before I invest time in using this I want to know that this fundamental feature is actually supported.

kellpossible commented 7 months ago

Hi @VorpalBlade , which localization system are you planning to use? Currently this library only supports gettext and fluent

VorpalBlade commented 7 months ago

I'm not sure yet! I have tried to figure out to what extent fluent and gettext support mixed locales, without a great deal of success.

I'm actually leaning towards trying to use icu4x, but there message handling isn't implemented yet. It does however properly handle data formatting. Gettext seems to only do messages if I understand things correctly. And with fluent I haven't figured it out, and havent gotten any replies to my questions either.

kellpossible commented 7 months ago

I haven't tested yet, to be sure but I think maybe locale number formatting functionality is not yet available in the Rust implementation of fluent? Anyway I think you could probably combine icu4x with fluent using https://docs.rs/fluent/latest/fluent/bundle/struct.FluentBundle.html#method.add_function to implement this yourself, and https://docs.rs/i18n-embed/latest/i18n_embed/fluent/struct.FluentLanguageLoader.html#method.with_bundles_mut to modify the fluent bundle with this system. You could implement it in a way that places priority to the LC_NUMERIC environment variable if present.

kellpossible commented 7 months ago

As for gettext, I'm not sure, I haven't given any thought to the question yet. We currently use https://github.com/rust-locale/locale_config/ for https://docs.rs/i18n-embed/latest/i18n_embed/struct.DesktopLanguageRequester.html implementation, so if that library supports LC_NUMERIC then we can hopefully add support to it for gettext if it's not already working.

VorpalBlade commented 7 months ago

Do note it is not just LC_NUMERIC, POSIX defines a bunch of these for date formatting, measurements, sorting order, etc. But whatever solution is applied for one of them will likely be similar for all of them.

alerque commented 4 months ago

Number formatting based on locales is indeed not implemented at the moment in the Fluent crate(s). There is work in progress to use icu4x (fluent-rs#269 and fluent-rs#269) as well as provide the NUMBER() built in (fluent-rs#353). A DATETIME() implementation was also pointed out although not contributed yet (fluent-rs#181). Contributions are welcome and now that there are a couple more community maintainers we should actually be able to facilitate contributions getting merged and released.

Are there other pieces needed from the Fluent end of things related to this issue?