Using xgettext and internationalization Topic is solved

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
Rabah
Earned some good credits
Earned some good credits
Posts: 133
Joined: Fri Jun 08, 2007 8:21 am

Using xgettext and internationalization

Post by Rabah »

Dears,

refering this topic http://forums.wxwidgets.org/viewtopic.php?t=15116 :cry: . It is my alternative on MAC for internationaization

I tried to use xgettext I have some questions :

first af all : How using xgettext? is it a kind of frameworks?

then : about the portable object file (.po). How we use the .po file "generated" and how code the xgettext?
Must I translate my string and put them in the .po, is it right?

-> using xgettext is using the macro #define _(x) xgettext(x) ??

Great thanks

Rabah
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte »

:idea: First, look at T-Rex's blog and the internat sample.

:idea: Then, download/install the gettext package (from GNU.org for example, or the gnuwin32 project on SourceForge if you wish to generate the .po files on your Windows environment).

:arrow: Now, what I did in my app:
I have a batch that generates the .po files for all my so-called "domains".
"%1" being the language I prepare the translations for
-C means C++ files
-k_ means to extract all strings marked with the _ macro (you can add other macros "-kBAR -kFOO" in the same command line)
-fsources.txt "sources.txt" is the name of the file with the list of .h and .cpp files to extract the strings from

Code: Select all

@xgettext -C -k_ -fsources.txt -D.. --from-code=cp1252 --output-dir=%1 --default-domain=my-app-current 
@msgmerge --no-wrap -U %1\my-app.po %1\my-app-current.po
the msgmerge command is called to merge previous translations with newly extracted strings (I don't want to re-translate everything at each extraction 8) )

Then, some use poEdit, I simply use my prefered text editor, and I fill the .po files.

When, you're there, you can re-have a look at T-Rex blog to look how to modify your app to load the .po files, set the wxLocale corresponding to the "user prefered language" setting, and that's all :!:


See also:
:arrow: a thread about wxLocale
:arrow: another thread about multi-lines text constants (you may face the same problem)
Rabah
Earned some good credits
Earned some good credits
Posts: 133
Joined: Fri Jun 08, 2007 8:21 am

Post by Rabah »

benedicte wrote: :arrow: Now, what I did in my app:
I have a batch that generates the .po files for all my so-called "domains".
"%1" being the language I prepare the translations for
-C means C++ files
-k_ means to extract all strings marked with the _ macro (you can add other macros "-kBAR -kFOO" in the same command line)
-fsources.txt "sources.txt" is the name of the file with the list of .h and .cpp files to extract the strings from

Code: Select all

@xgettext -C -k_ -fsources.txt -D.. --from-code=cp1252 --output-dir=%1 --default-domain=my-app-current 
@msgmerge --no-wrap -U %1\my-app.po %1\my-app-current.po
the msgmerge command is called to merge previous translations with newly extracted strings (I don't want to re-translate everything at each extraction 8) )
Thanks Benedicte for all your precisions but,
(My app?) Please precise me where you code this?
And is it C++ code?
it seems to be terminale commands, LINUX? (am I wrong? -> sorry).
I am on MAC OS 10 and am a very newer on this OS.


Does exist the project for MAC Os environment? or the windows one is available?

Regards
Rabah
mc2r
wxWorld Domination!
wxWorld Domination!
Posts: 1195
Joined: Thu Feb 22, 2007 4:47 pm
Location: Denver, Co
Contact:

Post by mc2r »

xgettext is an application that extracts strings from your source code and generates a .po for you.

going to http://www.google.com and typing xgettext will tell you more about xgettext in general.

searching the forum here also would answer these questions for you. http://forums.wxwidgets.org/search.php type xgettext and read.

You can also try http://wxwidgets.info/?q=wxTranslation which you would have found had you searched the forum for xgettext.

-Max
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte »

Rabah wrote: ...
Thanks Benedicte for all your precisions but,
(My app?) Please precise me where you code this?
And is it C++ code?
it seems to be terminale commands, LINUX? (am I wrong? -> sorry).
I am on MAC OS 10 and am a very newer on this OS.


Does exist the project for MAC Os environment? or the windows one is available?

Regards
Rabah
the commands are shell script for Windows, but can be adapted to any Linux shell.
Try to search for "xgettext" in this forum, you'll find several messages for your questions.
Last edited by benedicte on Sat Jul 21, 2007 6:34 am, edited 1 time in total.
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

i posted something on your other thread
http://forums.wxwidgets.org/viewtopic.php?t=15116

the mac shell is in the /Applications/Utilities folder, it is called 'Terminal'
Rabah
Earned some good credits
Earned some good credits
Posts: 133
Joined: Fri Jun 08, 2007 8:21 am

Post by Rabah »

benedicte wrote: :arrow: Now, what I did in my app:
I have a batch that generates the .po files for all my so-called "domains".
"%1" being the language I prepare the translations for
-C means C++ files
-k_ means to extract all strings marked with the _ macro (you can add other macros "-kBAR -kFOO" in the same command line)
-fsources.txt "sources.txt" is the name of the file with the list of .h and .cpp files to extract the strings from

Code: Select all

@xgettext -C -k_ -fsources.txt -D.. --from-code=cp1252 --output-dir=%1 --default-domain=my-app-current 
@msgmerge --no-wrap -U %1\my-app.po %1\my-app-current.po
Dears wxCoders,
Hello benedicte,

I managed to implemente my code for internationalization but I started with windows to understand the principle before working on Mac 0SX.

I would like some precisions about values on your batch : what does "cp1252" mean? And why do you precise "no wrap" in the msgmerge command?

Moreover At this time I generated my .po files and translate them. after I generated the .mo files.
I create a locale in My app as following but it does not function

Code: Select all

wxLocale m_locale;
int langue = m_locale.GetSystemLanguage();
	m_locale.Init(langue,wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING);
Must I place the files .po an d.mo in a specific directory?

Regards
Rabah
Rabah
Earned some good credits
Earned some good credits
Posts: 133
Joined: Fri Jun 08, 2007 8:21 am

Post by Rabah »

Dears I carried on with this code

Could someone find the errors about this code. I do not have my app translated.

Code: Select all

bool MyApp::OnInit()
{		
	m_locale.AddCatalogLookupPathPrefix(wxT("C:\Projects\LaPassword\locale\fr_FR\LC_MESSAGES"));
m_locale.AddCatalog(wxT("messages.mo"));
int langue = m_locale.GetSystemLanguage();
m_locale.Init(langue,wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING);
	
	wxInitAllImageHandlers(); 
	
	FrameWizard * framewiz = new FrameWizard(NULL,-1,
							_("Wizard : Welcome"),
	wxPoint(300,300),
	wxSize(610,375),0|
         wxDEFAULT_FRAME_STYLE);

         framewiz->Show(true);
	framewiz->SetFont(wxFont(10, wxSWISS , wxNORMAL, wxNORMAL, false,"futura"));
	SetTopWindow(framewiz);
	return TRUE;
} 
Regards

Rabah
tan
wxWorld Domination!
wxWorld Domination!
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Post by tan »

Hi,
i do it thus:

Code: Select all

m_locale.Init(sys_lang);			// set custom locale (in my case it is "ru")
m_locale.AddCatalogLookupPathPrefix("locale");	// set "locale" prefix
// note: without any language, it will set by init (really my .mo files are in "my_work_dir/locale/ru/*.mo")

m_locale.AddCatalog("wxproton");      		// our private domain (without extention)
m_locale.AddCatalog("wxstd");      		// wx common domain is default
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10
Rabah
Earned some good credits
Earned some good credits
Posts: 133
Joined: Fri Jun 08, 2007 8:21 am

Post by Rabah »

Hello tan,
thanks
In this case, please can you precise me what is a "catalog" (is it a .mo file?) and a "domain". it seems that calling the .mo files directly is not the right solution

Code: Select all

m_locale.Addcatalog("message.mo")
So I think I do not understand the two previous notions.

I thought that it functions as following :
1) declare a locale wxLocale m_locale;
2) load the locale setting of the user and recognize the language m_locale.Init(...);
3) the app goes to the right directory work_dir/locale/fr_FR/LC_MESSAGES fr_FR (for example)
4) the .mo file is in the directori and is called by the app
5) the language is adapted

is it right?

Rabah
tan
wxWorld Domination!
wxWorld Domination!
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Post by tan »

Hi, Rabah,
Rabah wrote:Hello tan,
thanks
In this case, please can you precise me what is a "catalog" (is it a .mo file?) and a "domain".
catalog and domain IMO is equal. And yes, it is .mo file name.
Rabah wrote: it seems that calling the .mo files directly is not the right solution

Code: Select all

m_locale.Addcatalog("message.mo")
AFAIK it is the same, extention will be added if it absents.
Rabah wrote: I thought that it functions as following :
1) declare a locale wxLocale m_locale;
2) load the locale setting of the user and recognize the language m_locale.Init(...);
3) the app goes to the right directory work_dir/locale/fr_FR/LC_MESSAGES fr_FR (for example)
I think it is redundant, quite enough work_dir/locale, because in m_locale.Init(lang), current lang was setted (fr_FR, f.e.).
LC_MESSAGES is optional (it will work with it and without)
(this behaviour is default for 2.8, AFAIR in 2.6 LC_MESSAGE was mandatory)
Rabah wrote: 4) the .mo file is in the directori and is called by the app
5) the language is adapted

is it right?

Rabah
Yes it is.
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10
Rabah
Earned some good credits
Earned some good credits
Posts: 133
Joined: Fri Jun 08, 2007 8:21 am

Post by Rabah »

Great thanks!!!
Post Reply