I want to use gettext for i18n. But I need to translate messeges to a different languages. Is it possible to specify a locale for a one gettext call?
3 Answers
If you use multiple threads then you can use gettext if you use the locale-related facilities specified in POSIX.1-2008 (and implemented in GLIBC 2.3). The key function you would use is uselocale
, which is a bit like setlocale
but for the current thread only.
If you are using Windows then you are out of luck--MSVCRT does not provide an equivalent to uselocale
, and I believe on that platform libintl emulates setlocale
itself, in a non-thread-safe way IIRC.

- 1,858
- 1
- 17
- 18
As you can see from Replacements for gettext I had similar problems, only it gets worse if you have to support more platforms.
Basically gettext is only really suitable for single-threaded interactive programs.
If you have the chance then a different translation system (ICU looks quite nice).
Otherwise there are a few libraries that read .mo files directly, and can provide the translation as you want:

- 1
- 1

- 52,368
- 9
- 94
- 137
I want to use gettext for i18n. But I need to translate messeges to a different languages.
If your application is single threaded you may switch locale, otherwise you can't use gettext library for this purpose.
Is it possible to specify a locale for a one gettext call?
You may use Unofficial Boost library Boost.Locale that supports gettext message catalogs. But it is C++
only.

- 31,019
- 21
- 127
- 215