Multilingual application

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.
User avatar
Nucleorion
Knows some wx things
Knows some wx things
Posts: 45
Joined: Sat Jan 07, 2017 10:08 pm

Re: Multilingual application

Post by Nucleorion »

I also try:

Code: Select all

	m_locale.Init(wxLANGUAGE_ENGLISH, wxLOCALE_CONV_ENCODING); //wxLOCALE_CONV_ENCODING Deprecated
	wxLocale::AddCatalogLookupPathPrefix(wxT(".\\langs"));
	m_locale.AddCatalog(wxT("es_ES"));
But it does not work either
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Multilingual application

Post by doublemax »

Try a tool like Procmon and check in which paths the executable is looking for the translation files.

I use my own translation solution for my own texts, but for the wxWidgets translation files, i had to put them in this path:

Code: Select all

<exedir>/locale/de_DE/wxstd.mo
Use the source, Luke!
User avatar
Nucleorion
Knows some wx things
Knows some wx things
Posts: 45
Joined: Sat Jan 07, 2017 10:08 pm

Re: Multilingual application

Post by Nucleorion »

Procmon = Process monitor?

I get this:
Image
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Multilingual application

Post by PB »

You may also check the output of the i18 debug trace, which shows the looked-up paths and files, as described here viewtopic.php?f=1&t=42414#p171997
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Multilingual application

Post by doublemax »

ProcMon: https://technet.microsoft.com/en-us/sys ... nitor.aspx

Add a filter so that it only displays output for your exe and let it show only file events. You will still get hundreds of events when you start your app.
Use the source, Luke!
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: Multilingual application

Post by eranon »

Hello,

In my own codes, I manage location of the language catalogs like this:

Code: Select all

    #ifdef __WXMSW__
    #ifdef _DEBUG
    m_strLangsBase = ::NormalizePathSep(wxPathOnly(argv[0]) + "/../../lang");
    #else
    m_strLangsBase = ::NormalizePathSep(wxPathOnly(argv[0]) + "/lang");
    #endif
    #endif // __WXMSW__
    #ifdef __WXOSX__
    m_strLangsBase = ::NormalizePathSep(wxPathOnly(argv[0]) + "/../Resources");
    #endif // __WXOSX__
Also, just an added info on a secondary point : as stated at http://docs.wxwidgets.org/trunk/group__ ... 96ec864160, I quote:
Note that since wxWidgets 2.9.0 you shouldn't use wxT() anymore in your program sources (it was previously required if you wanted to support Unicode).
It's now implicit.
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
User avatar
Nucleorion
Knows some wx things
Knows some wx things
Posts: 45
Joined: Sat Jan 07, 2017 10:08 pm

Re: Multilingual application

Post by Nucleorion »

Image

I keep trying

I have made sure that the files are on the path but it still does not work

It would be ideal to find a turorial updated and explained in detail. I really do not understand how with the work that it costs to make these tools then there is hardly official documentation

About the routes it can not find I do not understand why you ask for them. Nowhere have I seen that I have to create anything in a folder called LC_MESSAGES as well as many others
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: Multilingual application

Post by eranon »

If you don't succeed with a relative path, go back to a known point and use an absolute harcoded one in your code for the moment. When all will be OK, you'll just have to fix this single point (since hardcoded absolute path is obviously not a good idea for your final release).

And to check if a file exists, you simply have wxFileExists() in stock.
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Multilingual application

Post by doublemax »

The ProcessMonitor output looks to me like the "es_ES" catalog is found. How do you check if it was successful?
Use the source, Luke!
User avatar
Nucleorion
Knows some wx things
Knows some wx things
Posts: 45
Joined: Sat Jan 07, 2017 10:08 pm

Re: Multilingual application

Post by Nucleorion »

eranon wrote:If you don't succeed with a relative path, go back to a known point and use an absolute harcoded one in your code for the moment. When all will be OK, you'll just have to fix this single point (since hardcoded absolute path is obviously not a good idea for your final release).

And to check if a file exists, you simply have wxFileExists() in stock.
How I use an absolute harcoded one?

How use wxFileExists() in this. I can't use for example

Code: Select all

wxFileExists(m_locale.AddCatalog(wxT("es_ES")))
doublemax wrote:The ProcessMonitor output looks to me like the "es_ES" catalog is found. How do you check if it was successful?
I don't understand doublemax. I don't know how check it. ProcessMonitor says some routes found and others not. What path are the right? All?
User avatar
Nucleorion
Knows some wx things
Knows some wx things
Posts: 45
Joined: Sat Jan 07, 2017 10:08 pm

Re: Multilingual application

Post by Nucleorion »

Whell, first error:

Code: Select all

	m_locale.Init(wxLANGUAGE_SPANISH);//Init to the spanish
	wxLocale::AddCatalogLookupPathPrefix(wxT(".\\langs"));//add path
	m_locale.AddCatalog( wxT ("es"));//add catalog wxWidgetspath/locale/es.mo
	m_locale.AddCatalog(wxT("es_ES"));//add my .mo edit files
Move this lines before //(*AppInitialize

So

Code: Select all

	m_locale.Init(wxLANGUAGE_SPANISH);//Init to the spanish
	wxLocale::AddCatalogLookupPathPrefix(wxT(".\\langs"));//add path
	m_locale.AddCatalog( wxT ("es"));//add catalog wxWidgetspath/locale/es.mo
	m_locale.AddCatalog(wxT("es_ES"));//add my .mo edit files
    //(*AppInitialize
    bool wxsOK = true;
    wxInitAllImageHandlers();
    if ( wxsOK )
    {
    	MultilingualExampleFrame* Frame = new MultilingualExampleFrame(0);
    	Frame->Show();
    	SetTopWindow(Frame);
    }
    //*)
Now load the default language right. The path is: lang\es_ES\es_ES.mo
User avatar
Nucleorion
Knows some wx things
Knows some wx things
Posts: 45
Joined: Sat Jan 07, 2017 10:08 pm

Re: Multilingual application

Post by Nucleorion »

For change language into to program I have a menu to set language.

Code: Select all

void MultilingualExampleFrame::OnMenu_Language_Spanish_Selected(wxCommandEvent& event)
{
	wxLocale* locale;
	long language=wxLANGUAGE_SPANISH;
	locale = new wxLocale( language );
	locale->AddCatalogLookupPathPrefix(wxT(".\\langs\\es_ES"));
	locale->AddCatalog( wxT ("es_ES.po"));
}
This change texts of parents windows but no in the main frame; menus, form, etc.

How I can set language in runtime?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Multilingual application

Post by doublemax »

How I can set language in runtime?
You can't - at least not with little effort. Store the new language, tell the user the app needs a restart and restart. As this doesn't happen often, i think it's an acceptable compromise.
Use the source, Luke!
User avatar
Nucleorion
Knows some wx things
Knows some wx things
Posts: 45
Joined: Sat Jan 07, 2017 10:08 pm

Re: Multilingual application

Post by Nucleorion »

Ok. Thanks Mate :)
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Multilingual application

Post by ONEEYEMAN »

Also keep in mind that sometimes additional software might be required to properly display international symbols.
Or just a properly generated locale on the system.

Thank you.
Post Reply