Koka / gettext-rs

GNU Gettext FFI binding for Rust
51 stars 25 forks source link

Query current language #96

Open piegamesde opened 2 years ago

piegamesde commented 2 years ago

I need to find out the current language, how can I do that? I see setlocale, but no getter

Minoru commented 2 years ago

Oops! In C, you'd just pass NULL into setlocale, but our safe bindings prohibit that. For now, you can call gettext_sys::setlocale(category, std::ptr::null), but we should really change the safe wrapper to allow this (or just write a separate getter).

piegamesde commented 1 year ago

So I tried out gettext_sys::setlocale for quering it, not sure which category I need to use. It returns "C" for LcAll and "German_germany.1252" for LcCType and LcMessages on a Windows machine set to German.

(On Linux I get correct looking values so maybe this is not a bindings issue)

Minoru commented 9 months ago

LcMessages is the right category for this, see https://www.gnu.org/software/libc/manual/html_node/Locale-Categories.html. The returned value is a locale, whose format is described in https://www.gnu.org/software/libc/manual/html_node/Locale-Names.html. You need to extract the part before the first _ to get the language.