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

Query current language

Open piegamesde opened this issue 3 years ago • 3 comments

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

piegamesde avatar Jun 20 '22 14:06 piegamesde

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).

Minoru avatar Jun 21 '22 18:06 Minoru

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)

piegamesde avatar Dec 26 '22 18:12 piegamesde

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.

Minoru avatar Sep 16 '23 17:09 Minoru