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

Multilingual application

Post by Nucleorion »

Any tutorial for implement multilinguan function.

I try with poedit follow this tutorial:
http://www.gsy-design.com/how-to-genera ... ng-poedit/

But they no find any string

I try also change parameter according to the page:
https://wiki.wxwidgets.org/Internationalization

thanks
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Multilingual application

Post by doublemax »

Are your text literals wrapped in the _() macro?

Other than that, there really is not much that can go wrong.

Also, check the "official" wxWidgets page on that topic:
http://docs.wxwidgets.org/trunk/overview_i18n.html
Use the source, Luke!
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 »

Hi,
Did you try the internat sample?
Also, make sure you put you translation files into the directory where they can be found.

Thank you.
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 »

Yes, I have _("Button") texts and tags of controls are generated with _() for codeblocks and wxwidgets.

I put .po and .mo files together .cpp files but I dont fill .po file, Only I have header.

en_US.po

Code: Select all

msgid ""
msgstr ""
"Project-Id-Version: rf2pl\n"
"POT-Creation-Date: 2017-02-17 10:57+0100\n"
"PO-Revision-Date: 2017-02-17 10:58+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: en_US\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.8.11\n"
"X-Poedit-Basepath: .\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: _(\n"
"X-Poedit-SearchPath-0: .\n"
I cant find strings with poedit to fill .po or create .pot file
Nunki
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 235
Joined: Fri Sep 14, 2012 8:26 am
Location: Kontich, Belgium
Contact:

Re: Multilingual application

Post by Nunki »

Why not take the xrc approach. With dialogblocks I create the GUI screens and let it create the xrc files instead of c++ code. I copy all these xml files into a ./xrc/nld or ./xrc/eng directory, depending on the language used. A language code associated with a login makes the application load the right xrc files, thus providing the screens in the right language.
Only for fixed texts, I use the database to store strings in several languages with an identifier. So they can be loaded at startup as well.
This approach gives you the ability that, though the pc may be in dutch or german, for example, when a user is french, at login his application wil run in his language.
And above all, your code stays the same, regardless.

Nunki.
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 »

Thk for all :)

Finally I extract text setting _ how keyword for _("My text") and setting ‪xgettext --force-po -o %o %C %K %F in order for extraction.

I have already translated strings and I have created .po and .mo files.

But how do I now for the user to choose one language or another?
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 »

Hi,
Did you run the "internat" sample?
Also, the default language is determined by locale.

Thank you.
delt
Knows some wx things
Knows some wx things
Posts: 27
Joined: Mon Dec 26, 2016 11:17 pm

Re: Multilingual application

Post by delt »

I was meaning to also ask about this. I'm familiar with using gettext/libintl with non-wxWidgets projects, but how does it work with wxWidgets when it comes to redistributing/selecting .mo files? For example, is there a way to embed them in the executable, and not have to redistribute a whole directory structure for the locale stuff?
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 »

Hi,
Like I said, run the internat sample and then look at the code.
Embed the translation is not possible, you will have to distribute separate files.

Thank you.
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 »

delt wrote:I was meaning to also ask about this. I'm familiar with using gettext/libintl with non-wxWidgets projects, but how does it work with wxWidgets when it comes to redistributing/selecting .mo files? For example, is there a way to embed them in the executable, and not have to redistribute a whole directory structure for the locale stuff?
It depends on the operating system you target. On Mac for example, an app bundle (.app) is already a tree with directories and files inside, then you don't have to deploy any .mo outside of the bundle.

However, all mechanisms are always possible, even if it's not the standard. You can embed what you want in an executable (even an exe in an exe) and generate what file you want on disk when you decide: for example, generate the .mo from your app itself on the first launch... But, frankly, it's an added work while it's very easy to simply copy these .mo from your installer.
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
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 »

ONEEYEMAN wrote:Embed the translation is not possible, you will have to distribute separate files.
Actually, I have never used it but wxWidgets do directly support .mo files embedded into the executable, at least on MS Windows:
http://docs.wxwidgets.org/trunk/classwx ... oader.html
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 »

Thank you very much!
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 like store translate files in folder .//langs

Then I have langs folder with mo and po files cuatriplicated for prevent wrong ubication
MyAppPath\es_ES.mo
MyAppPath\langs\es_ES.mo
MyAppPath\bin\langs\es_ES.mo
MyAppPath\bin\Debug\langs\es_ES.mo

I try follow the video https://wxwidgets.info/localization_video/

Then I type in MyApp.h

Code: Select all

        wxLocale m_locale; 
In MyApp.cpp in bool MultilingualExampleApp::OnInit()

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(_("es_ES"));//add my .mo edit files
	
but when I run my app the language is not changed
Manolo
Can't get richer than this
Can't get richer than this
Posts: 827
Joined: Mon Apr 30, 2012 11:07 pm

Re: Multilingual application

Post by Manolo »

As Oneeyeman suggested, follow "internat" sample. See the differences to your code.
Post Reply