cargo-i18n icon indicating copy to clipboard operation
cargo-i18n copied to clipboard

Mixed locale support?

Open VorpalBlade opened this issue 1 year ago • 6 comments

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.

VorpalBlade avatar Feb 04 '24 21:02 VorpalBlade

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

kellpossible avatar Feb 12 '24 14:02 kellpossible

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.

VorpalBlade avatar Feb 12 '24 14:02 VorpalBlade

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 avatar Feb 12 '24 15:02 kellpossible

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.

kellpossible avatar Feb 12 '24 15:02 kellpossible

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.

VorpalBlade avatar Feb 12 '24 15:02 VorpalBlade

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?

alerque avatar May 06 '24 13:05 alerque