gettext-rs icon indicating copy to clipboard operation
gettext-rs copied to clipboard

Add `getters::getlocale`

Open timotheos-firestone opened this issue 3 years ago • 5 comments

Add a way to get the current active locale by passing in a null pointer to the C setlocale function, which is documented to be the way to query the locale; without this, there is no way for users of this library to query the current locale.

timotheos-firestone avatar Aug 14 '22 03:08 timotheos-firestone

I added this functionality because it is useful, at least, for debugging; for example, an issue I am having with setlocale() :)

timotheos-firestone avatar Aug 14 '22 03:08 timotheos-firestone

BTW you can ignore the CI failure for musl. I am meaning to fix it, but haven't yet figured out how (#99).

Minoru avatar Aug 19 '22 14:08 Minoru

Hey @timotheos-firestone, gentle ping ;) I haven't done anything about the musl CI yet, but this PR doesn't depend on musl, so it can be merged regardless. Would you like to finish this?

Minoru avatar Dec 11 '22 14:12 Minoru

I might be in the mood of taking this over. Would you mind if I change the return type of setlocale to Result<(), ()>?

I can add tests, just need some guidance as to what needs to be done

piegamesde avatar Dec 16 '22 20:12 piegamesde

Would you mind if I change the return type of setlocale to Result<(), ()>?

I'm very hesitant to do that because this loses the information that the underlying C function returns. But clearly you have a reason to change the type; can you share the thinking behind that?

I can add tests, just need some guidance as to what needs to be done

The smoke test I had in mind goes something like this:

let original_from_getlocale = getlocale();
let original_from_setlocale = setlocale(LC_ALL, "en_US.UTF-8");
assert_eq!(original_from_getlocale, original_from_setlocale);
let en_us_utf8 = setlocale(LC_ALL, original_from_getlocale);
assert_eq!(en_us_utf8, "en_US.UTF-8");
let restored = getlocale();
assert_eq!(restored, original_from_getlocale);

it has to be a separate integration test. We can't put it into tests/integration.rs because the tests there rely on the shared environment where the locale doesn't change.

Minoru avatar Jul 20 '24 10:07 Minoru