gettext on win32 issue

Hi all,

I am having an issue using gettext to translate a GTKmm application in
win32 (it works fine on Linux). My build environment is based on MSYS
and I've tried to build the app with both the GTKmm 2.16 and GTKmm
2.20 installers I've found here:

Basically when I run the app (in Windows), gettext works fine for the
following strings:
 + Custom gtk objects, like default buttons (OK or cancel) or default
menus (archive, new exit, etc)
 + Strings that are translated at execution time with a call to _()
(both in console or in the GUI)

But it fails when the string is static and marked as translatable with
N() but my application never calls to _() explicitely. Basically there
are 2 kinds of strings that are not translated:
 + Those included in the GOptionEntry list, which show the available
options that can be passed to the program through command line
 + Strings included in the .glade file that never change during the
execution of the application, for example a menu called "Game", or a
label that contains the word "rotate"

It looks like I'm missing something that somehow gets done on Linux
automatically, but that is necessary on Windows. Here's the offending
code related to the issue (a bit cleaned up so it can be "easily"

/* ... */
static GOptionEntry g_cmdEntries[] =
    { "version", 0, 0, G_OPTION_ARG_NONE, &g_version,
      N_("Prints current version of the software and exists"),
      NULL },

    /* and much more that are declared in the same way */

    { NULL }

/* ... */

static GOptionContext* g_cmdContext = NULL;

/* ... */

int main(int argc, char **argv)
    GError* error = NULL;
    char    errorStringBuffer[ERROR_STRING_BUFFER_SIZE];

    // I've tested the following with no luck:
    // + calling to setlocale (LC_ALL, ""); alone,
    // + calling to gtk_set_locale(); without calling previusly to
gtk_disable_setlocale ();
    // + And the code already present here (which looked to me the
most correct reading the doc)
    gtk_disable_setlocale ();
    //setlocale (LC_ALL, "");

    // i18n initialisation
    // make sure first that the message catalog can be found
    if (bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR) != NULL)
        // UTF-8 chosen as codeset
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
        // initialise the message catalog
        textdomain (GETTEXT_PACKAGE);
        // if the locale could not be set, trying to localise this string
        // doesn't make a lot of sense
        std::cerr << "Error while setting the locale" << std::endl;

    // This string is correctly translated. Note it calls _(), so it's
translated at running time
    g_cmdContext = g_option_context_new (_("- The GNU polyominoes board game"));

    g_option_context_add_main_entries (g_cmdContext, g_cmdEntries,

    g_option_context_set_translation_domain (g_cmdContext, GETTEXT_PACKAGE);

    GOptionGroup* grp = gtk_get_option_group (TRUE);

    g_option_context_add_group (g_cmdContext, grp);

    g_option_group_set_translation_domain (grp, GETTEXT_PACKAGE);
    if (!g_option_context_parse (g_cmdContext, &argc, &argv, &error))
        std::stringstream errMessage;
        errMessage << _("Error parsing command line")
                   << ": "
                   << error->message;

        FatalError(argv[0], errMessage.str().c_str(), COMMAND_LINE_PARSING_ERR);

    /* some code handling the command line options parsed by gtk */

    /* ... If the user chose to show the GUI ... */

    Gtk::Main kit(argc, argv);
    Glib::RefPtr<Gtk::Builder> gtkBuilder = Gtk::Builder::create();

    // retrieve the glade definitions from the object mebedded in the .exe file
                    reinterpret_cast<const char *>(__BIN_GUI_GLADE_START__),
                    reinterpret_cast<long int>(__BIN_GUI_GLADE_SIZE__))

    MainWindow *pMainWindow = NULL;
    gtkBuilder->get_widget_derived(GUI_MAIN_WINDOW_NAME, pMainWindow);

    if (pMainWindow  != NULL)*pMainWindow);

Can anybody see what is happening? I've tried everything I've found on
the internet, but no luck so far translating those "static" strings.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]