Jump to content
  • Advertisement
Iggnaccy

C++ GNU gettext not working

This topic is 441 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi!

Recently, I was trying to get GNU gettext to work, and I encountered a weird problem: it all translates just fine, but only to the system language. No matter what I pass to setlocale, it doesn't change the language.

My file hierarchy looks basically like that:

Project folder ->
    locale ->
        en_US ->
            LC_MESSAGES ->
                domain.mo & domain.po
        pl_PL ->
            LC_MESSAGES ->
                domain_pl.mo & domain_pl.po

Here's my code:

#include <iostream>
#include <libintl.h>
#include <locale>
#include <string>

using namespace std;

void selectLangDomain(const char* domain, const char* language)
{
    setlocale(LC_MESSAGES, language);
    bindtextdomain(domain, "./locale");
	textdomain(domain);
	cout << gettext("Hello world!") << endl;
    cout << gettext("Another message.") << endl;
}

int main()
{
    selectLangDomain("domain_pl", "pl_PL");
    selectLangDomain("domain", "en_US");
    return 0;
}

 

Share this post


Link to post
Share on other sites
Advertisement

Call setlocale(LC_ALL, "") and do putenv() with LANGUAGE environment variable set to desired language. Apparently gettext checks environment variables when choosing translation.

Share this post


Link to post
Share on other sites

Thank you for the answer, I tried using putenv and setenv, yet they seemed not to exist in my compiler (I was including stdlib.h), until I came home and tried there: it worked. Do you know what can I do to make these functions work on the other PC? Should I reinstall the compiler?

Share this post


Link to post
Share on other sites

putenv() should be in "stdlib.h". On windows there's _putinv() function in same stdlib.h. In my old app I had to undefine __STRICT_ANSI__ define before including stdlib.h when building for windows, can't remember now which building environment required that, probably mingw32.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!