Translation & Locale intialization

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Petru
Experienced Solver
Experienced Solver
Posts: 62
Joined: Sat Dec 31, 2011 1:05 pm
Contact:

Translation & Locale intialization

Postby Petru » Tue Jun 19, 2018 3:27 pm

Hi. I am having some trouble setting up the translation for my application. I am trying, for now, to create a translation to Romanian for my application, which goes by the name synodia. Here is what I have done:
  • I've extracted the _("") strings with xgettext into a po file.
  • I've translated them using PoEdit and compiled them into a mo file.
  • I've placed the mo file in the same directory with the executable file of my application, in synodia/ro/ro.mo
  • In terms of code, my current approach is:

Code: Select all

bool MyApp::OnInit() {
    bool wxsOK = true;
    wxLocale locale;
    wxTranslations* translations = new wxTranslations();
    wxFileTranslationsLoader* fileTranslationsLoader = new wxFileTranslationsLoader();
    fileTranslationsLoader->AddCatalogLookupPathPrefix(".");
    fileTranslationsLoader->LoadCatalog("synodia","ro");
    translations->SetLoader(fileTranslationsLoader);
    translations->AddCatalog("synodia");
    translations->SetLanguage("ro");
    wxTranslations::Set(translations);
    if (!locale.Init(wxLANGUAGE_ROMANIAN, wxLOCALE_DONT_LOAD_DEFAULT))
        std::cout << "Could not load translation";
       
///     .... etc

I don't get the "Could not load translation" message but the app still shows up untranslated. Any help much appreciated.
Petru Dimitriu, Romanian. wxWidgets 3.1 on Windows 7 & Ubuntu with MinGW/GCC + CLion

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 2785
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Translation & Locale intialization

Postby ONEEYEMAN » Tue Jun 19, 2018 3:44 pm

Hi,
Did you look at the internat sample?

Thank you.

Petru
Experienced Solver
Experienced Solver
Posts: 62
Joined: Sat Dec 31, 2011 1:05 pm
Contact:

Re: Translation & Locale intialization

Postby Petru » Tue Jun 19, 2018 9:46 pm

Surprising as it might seem, I did. Yet the sample does not provide any example of working with wxTranslations or wxTranslationsLoader. Anyway, after reading the sample again a few times, my current approach is:

Code: Select all

if (!locale.Init(wxLANGUAGE_ROMANIAN))
        std::cout << "Could not init"; // doesnt show up so should be fine, in theory

    locale.AddCatalog("synodia"); // false

    std::cout << wxLocale::IsAvailable(wxLANGUAGE_ROMANIAN); // true
    std::cout << locale.IsLoaded("synodia"); // false


The synodia.mo file is placed in /usr/share/locale/ro/LC_MESSAGES

Still no clue how this actually works.
Last edited by Petru on Wed Jun 20, 2018 7:42 am, edited 1 time in total.
Petru Dimitriu, Romanian. wxWidgets 3.1 on Windows 7 & Ubuntu with MinGW/GCC + CLion

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 2785
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Translation & Locale intialization

Postby ONEEYEMAN » Tue Jun 19, 2018 10:10 pm

Hi,
Where is IsLoaded() failed? Can you step thru the code and find out?
Also I presume there is nothing wrong with the AddCatalog() calls.

Thank you.

Petru
Experienced Solver
Experienced Solver
Posts: 62
Joined: Sat Dec 31, 2011 1:05 pm
Contact:

Re: Translation & Locale intialization

Postby Petru » Wed Jun 20, 2018 7:42 am

I forgot to mention that AddCatalog() also returns false. In fact, it returns false no matter what I try to load, even with names of files which are indeed located in /usr/share/locale/ro/LC_MESSAGES
As for the exact place where it fails, I'll have to compile wx with debug symbols for that, I'll work on it later.
Petru Dimitriu, Romanian. wxWidgets 3.1 on Windows 7 & Ubuntu with MinGW/GCC + CLion


Return to “C++ Development”

Who is online

Users browsing this forum: Google [Bot] and 25 guests