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

Postby Nucleorion » Fri Feb 17, 2017 10:29 am

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: 10905
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Multilingual application

Postby doublemax » Fri Feb 17, 2017 1:44 pm

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: 1698
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Multilingual application

Postby ONEEYEMAN » Fri Feb 17, 2017 3:51 pm

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

Postby Nucleorion » Mon Feb 20, 2017 2:46 pm

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
Earned some good credits
Earned some good credits
Posts: 110
Joined: Fri Sep 14, 2012 8:26 am
Location: Kontich, Belgium
Contact:

Re: Multilingual application

Postby Nunki » Mon Feb 20, 2017 8:19 pm

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

Postby Nucleorion » Wed Feb 22, 2017 6:55 am

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: 1698
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Multilingual application

Postby ONEEYEMAN » Wed Feb 22, 2017 7:08 am

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

Thank you.

delt
Earned a small fee
Earned a small fee
Posts: 16
Joined: Mon Dec 26, 2016 11:17 pm

Re: Multilingual application

Postby delt » Tue Feb 28, 2017 12:29 am

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: 1698
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Multilingual application

Postby ONEEYEMAN » Tue Feb 28, 2017 1:05 am

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
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 555
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: Multilingual application

Postby eranon » Tue Feb 28, 2017 11:49 am

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
wxWorld Domination!
wxWorld Domination!
Posts: 1185
Joined: Sun Jan 03, 2010 5:45 pm

Re: Multilingual application

Postby PB » Tue Feb 28, 2017 1:43 pm

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_resource_translations_loader.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

Postby Nucleorion » Tue Feb 28, 2017 3:41 pm

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

Postby Nucleorion » Thu Mar 16, 2017 12:34 pm

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
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 500
Joined: Mon Apr 30, 2012 11:07 pm

Re: Multilingual application

Postby Manolo » Thu Mar 16, 2017 5:14 pm

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


Return to “C++ Development”

Who is online

Users browsing this forum: Bing [Bot] and 8 guests