Are strings hard-coded in wxWidgets!? Topic is solved

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.
Post Reply
cpp
I live to help wx-kind
I live to help wx-kind
Posts: 195
Joined: Wed Sep 28, 2005 9:42 pm

Are strings hard-coded in wxWidgets!?

Post by cpp »

Hi!, if i write this simple code:

Code: Select all

wxString someText = wxGetTextFromUser("Whatever");
it works as expected (sort of), a nice dialog appears, asking the user for the text, the only "small" problem is, that even to the locale in my PC is set to Spanish-Mexico (it in fact has the spanish version of Windows XP), the ok button sais "Ok" and the cancel button "Cancel" ALL IN ENGLISH!, did further testing, and it seems like ALL messages/strings comming from wxWidgets are allways in english!, i tried creating a wxLocale object set to spanish inside my app
User avatar
ABX
Can't get richer than this
Can't get richer than this
Posts: 810
Joined: Mon Sep 06, 2004 1:43 pm
Location: Poznan, Poland
Contact:

Re: Are strings hard-coded in wxWidgets!?

Post by ABX »

cpp wrote:how do i make it use spanish rather than english?
I would start from studying wxWidgets/samples/internat sample and from reading http://www.wxwidgets.org/manuals/2.6.2/ ... ation.html

Hope this helps,

ABX
CVS Head, 2.8.X
wxMSW, wxWinCE, wxPalmOS, wxOS2, wxMGL, bakefile
gcc 3.2.3, bcc 5.51, dmc 8.48, ow 1.6, vc 7.1, evc 3/4, pods 1.2
cpp
I live to help wx-kind
I live to help wx-kind
Posts: 195
Joined: Wed Sep 28, 2005 9:42 pm

Post by cpp »

Thanks for your answer,
I would start from studying wxWidgets/samples/internat sample
In fact that is where i started, the funny thing is, that running the sample, no matter what language i select when it starts, when you select "play a game", and the text input dialog comes up (via wxGetTextFromUser()), the buttons ARE still in english, even if i selected german, system default, or whatever earlier, thats why i ask if the strings in wxWidgets are hard coded.

As for reading the info in Internationalization, i did that also, thats where it sais "wxWidgets its itself translated to several languages" and that i should "consult wxWidgets home page for the most up-to-date translations", wich i did, but i guess i totally *stink* at searching, cause i couldn find any.
I assume i need to recompile wxWidgets using one of those "translations" i cant find. Is this correct? if so where do i find these translations?
Thanks!
upCASE
Moderator
Moderator
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE »

cpp wrote: I assume i need to recompile wxWidgets using one of those "translations" i cant find. Is this correct? if so where do i find these translations?
No, you don't need to recompile.
wxWidgets uses a mechanism like gnu gettext. You need to have a "compiled" catalog for each language that wxWidgets will load and use to translate the text that were enclosed by the _() macro.

I confess this might be a bit confusing when first using it.
First, get poEdit (http://www.poedit.org/). It allows you to scan sources for strings enclosed by _(), meaning they should be translated. You can add the translations with poEdit. For example, install poEdit and go to the internat sample dir and look e.g. at the de directory. Open the intenat.po file with poEdit. You will see the original strings and the translated ones. When saving the catalog, poEdit automaticaly creates the binary version of this catalog (a .mo file). This is the file wxWidgets will look for and load at line 193 ( m_locale.AddCatalog()) in the internat.cpp.
Which file from what language dir is used depends on what you specified with m_locale.Init(). For wxLANGUAGE_GERMAN the dir is de, for wxLANGUAGE_POLISH it is pl. The catalog has to be in this directory.

For the "standard" wxWidgets strings you'll have to do about the same. Look in WXDIR\locale and you'll find translations for 28 languages in the po format. Open one of these and let poEdit create the .mo file. IHMO it's best to rename the file to wx.mo and copy the file to the correct language dir in the sample folder. Then, add a line to internat.cpp like
m_locale.AddCatalog(wxT("wx"));
Now the sample should have all the strings translated.

Sorry if I confused you even more. I'm just having my first cup of coffee :)

Basically it's:
1. Create the catalogs
2. Place them in a sensefull dir structure
3. use wxLocale::Init() to tell wxWidgets what language to use
4. use wxLocale::AddCatalogLookupPathPrefix() to specify the path where the catalogs should be searched for
5. use wxLocale::AddCatalog() to actualy add the catalog

How you create the dir structure and name the files is up to you. If the translation can't be found, the original strings is used.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
cpp
I live to help wx-kind
I live to help wx-kind
Posts: 195
Joined: Wed Sep 28, 2005 9:42 pm

Post by cpp »

Sorry if I confused you even more.
on the contrary! you cleared up most my doubts!
Sorry about being such a PITA on this but
wxWidgets uses a mechanism like gnu gettext
to be honest, i have *not a clue* of what gnu gettext is, that why (before you explaination) i dint understand all this po, mo stuff :oops:

If i may be a PITA for just a little longer :D
im getting poedit right now, and ibe located the po files in my wxdir, the deal is, i (for now at least) have no intention or need to provide multy-language support for my apps (my clients are all spanish speaking), all i need is that wxWidgets displays ->its own standard<- messages/labels in spanish rather than english, for example, if i call the wxGetTextFromUser(...) function, i want the dialog to have its ok and cancel button captions in spanish.
However, (if i understood you correctly), to have wxWidgets display its "standard" texts in spanish, i would still have to distribute the proper compiled spanish catalog (the spanish one in the WXDIR/locales) with my application
upCASE
Moderator
Moderator
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE »

[quote="cpp"](please say no! :( )
inst there a way i could compile a "spanish version" of wxWidgets that does not require me to distribute a catalog alongside my app
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
cpp
I live to help wx-kind
I live to help wx-kind
Posts: 195
Joined: Wed Sep 28, 2005 9:42 pm

Post by cpp »

oh boy, this is a serius problem, one (actually my most important) client, demands that his apps are the .exe + database files only.
i guess ill have to inspect the wxWidgets sources and find a way to transalte them there (or re-consider using wxWidgets all together).

NE way, thank you very much for your help & patience.
User avatar
ABX
Can't get richer than this
Can't get richer than this
Posts: 810
Joined: Mon Sep 06, 2004 1:43 pm
Location: Poznan, Poland
Contact:

Post by ABX »

cpp wrote:oh boy, this is a serius problem, one (actually my most important) client, demands that his apps are the .exe + database files only.
i guess ill have to inspect the wxWidgets sources and find a way to transalte them there (or re-consider using wxWidgets all together).

NE way, thank you very much for your help & patience.
I suppose that modification of wxLocale::GetString(...) in wxW/src/common/intl.cpp could be done easily do get translated strings from other sources. Never needed that myself but you should be able to figure things from reading that source.

ABX
CVS Head, 2.8.X
wxMSW, wxWinCE, wxPalmOS, wxOS2, wxMGL, bakefile
gcc 3.2.3, bcc 5.51, dmc 8.48, ow 1.6, vc 7.1, evc 3/4, pods 1.2
prophet
Knows some wx things
Knows some wx things
Posts: 32
Joined: Wed Sep 01, 2004 6:19 am

Post by prophet »

I wrote a patch one to allow wxwidgets to read language files from a wxfilesystem. I have all my resources in a zip file, distributed with the application. Now i just add a wxfilesystem url to let wxwidgets load the language files from the zip file. The patch is here:

http://sourceforge.net/tracker/index.ph ... tid=309863


If you want to distribute only the exe file, you're gonna have a hard time. Because than you would have to incorperate the resources in your exe file (which is possible, look at those python "compilers" py2exe). But distributing a exe and zip file (xrs) is not too bad.
leio
Can't get richer than this
Can't get richer than this
Posts: 802
Joined: Mon Dec 27, 2004 10:46 am
Location: Estonia, Tallinn
Contact:

Post by leio »

I've always wondered if it were possible to dump the translation files as resources into a Windows exe file, and load them from there and use them. Maybe would involve a wxMemoryBuffer on the way, or similar, but is this a workable idea (for C++, at least)?
Compilers: gcc-3.3.6, gcc-3.4.5, gcc-4.0.2, gcc-4.1.0 and MSVC6
OS's: Gentoo Linux, WinXP; WX: CVS HEAD

Project Manager of wxMUD - http://wxmud.sf.net/
Developer of wxGTK;
gtk+ port maintainer of OMGUI - http://www.omgui.org/
prophet
Knows some wx things
Knows some wx things
Posts: 32
Joined: Wed Sep 01, 2004 6:19 am

Post by prophet »

leio wrote:I've always wondered if it were possible to dump the translation files as resources into a Windows exe file, and load them from there and use them. Maybe would involve a wxMemoryBuffer on the way, or similar, but is this a workable idea (for C++, at least)?
Yeah, maybe you can write a wxFileSystem that loads from a resource. It's a bit tricky, but if you are handy with c++ i guess it's do-able.
cpp
I live to help wx-kind
I live to help wx-kind
Posts: 195
Joined: Wed Sep 28, 2005 9:42 pm

Post by cpp »

thanks for your replies guys, they gave me another idea:
A while back, i wrote an app wich required 4 (or was it 5?) binary files to work at run time, and using Visual Studio 6 i was able to "import them" as custom resources, then load them at runtime, and create the disk files from memory so the app could use them. Maybe i can do it like this, import the proper catalog(s) as custom/binary resources, and then read them, and write temp files containing the catalogs, then just pass the proper path prefix to wxLocale so it knows where to find them, and viola! load them from there. Of course this would only work for MSW (and its native resource system), but maybe i can find a way to "convert" the entire catalog into a static byte/char array, wich could be #included as needed in the applications, and therefore become part of it, kinda like the way images are converted to xpm. this would be 100% portable (not relying in W32 API resource calls).
Ill give it a shot and ill post my results here.

On a side note (and as a simple OPINION, *not* a critic), now i see why some books on C++ say that "one should NOT sprinkle string literals all over the code", if the strings in wxWidgets code where properly #defined
like wxTXT_CANCEL, wxTXT_OK, etc, all together in some .h file like wxTexts.h, and then #included when needed, making a full translation of them would be a heck of a lot easier. :wink:
leio
Can't get richer than this
Can't get richer than this
Posts: 802
Joined: Mon Dec 27, 2004 10:46 am
Location: Estonia, Tallinn
Contact:

Post by leio »

About translation catalogs on other platforms:

At least on POSIX/Linux system the catalogs go on a standard place, and no-one should complain about you distributing them as a separate file.
If you are installing only binaries into /opt, then I'm sure there are also conventions on where exactly (in /opt probably) the catalog files go.


About string literals

I don't really understand this.
gettext tools that generate the master .po file gather exact occurances together, and make you need to translate only one message for all the "Ok"-s and such. Don't see a reason to have such a header file, other than being able to easilly change the english representation in the string, majorly screwing every translation in existence in the process - in other words a (slightly) big no-no to change strings anyhow.
Compilers: gcc-3.3.6, gcc-3.4.5, gcc-4.0.2, gcc-4.1.0 and MSVC6
OS's: Gentoo Linux, WinXP; WX: CVS HEAD

Project Manager of wxMUD - http://wxmud.sf.net/
Developer of wxGTK;
gtk+ port maintainer of OMGUI - http://www.omgui.org/
cpp
I live to help wx-kind
I live to help wx-kind
Posts: 195
Joined: Wed Sep 28, 2005 9:42 pm

Post by cpp »

Thanks for your opinions.
At least on POSIX/Linux system the catalogs go on a standard place, and no-one should complain about you distributing them as a separate file.
well, the deal is, *none* of my clients uses linux. In fact, after working in computers and programing for several years here, the *only* linux installations ibe come to work with (other that a few network servers), were mine, about a year ago when i experimented with mandiva and fedora. (im back to windows now).
And about why some customers complain about extra files, its because they *think* they know "a lot" about software, and they had some TERRIBLE experiences in the past with Dll-Hell introduced into their lives by MS Visual Bashit (oops Basic) apps sold to them by other "developers". Yes, i know that a small mycat.mo file in the applications directory is 100% harmless since its not a dll or something that needs registering, but they (customers), that "know it all", think that they might create some hellish conflict in the system, so they wont have them. (attempting to convince them otherwise is almost allways pointless).
I don't really understand this.
gettext tools that generate the master .po file gather exact occurances together, and make you need to translate only one message for all the "Ok"-s and such. Don't see a reason to have such a header file,...
well, the reason would be precisely that, to have the app not need any extra .mo files.
Post Reply