Using xgettext and internationalization Topic is solved
Using xgettext and internationalization
Dears,
refering this topic http://forums.wxwidgets.org/viewtopic.php?t=15116 . 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
refering this topic http://forums.wxwidgets.org/viewtopic.php?t=15116 . 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
First, look at T-Rex's blog and the internat sample.
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).
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
the msgmerge command is called to merge previous translations with newly extracted strings (I don't want to re-translate everything at each extraction )
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:
a thread about wxLocale
another thread about multi-lines text constants (you may face the same problem)
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).
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
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:
a thread about wxLocale
another thread about multi-lines text constants (you may face the same problem)
Thanks Benedicte for all your precisions but,benedicte wrote: 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 fromthe msgmerge command is called to merge previous translations with newly extracted strings (I don't want to re-translate everything at each extraction )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
(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
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
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
the commands are shell script for Windows, but can be adapted to any Linux shell.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
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.
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'
http://forums.wxwidgets.org/viewtopic.php?t=15116
the mac shell is in the /Applications/Utilities folder, it is called 'Terminal'
Dears wxCoders,benedicte wrote: 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 fromCode: 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
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);
Regards
Rabah
Dears I carried on with this code
Could someone find the errors about this code. I do not have my app translated.
Regards
Rabah
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;
}
Rabah
-
- wxWorld Domination!
- Posts: 1471
- Joined: Tue Nov 14, 2006 7:58 am
- Location: Saint-Petersburg, Russia
Hi,
i do it thus:
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
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10
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
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
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")
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
-
- wxWorld Domination!
- Posts: 1471
- Joined: Tue Nov 14, 2006 7:58 am
- Location: Saint-Petersburg, Russia
Hi, Rabah,
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)
catalog and domain IMO is equal. And yes, it is .mo file name.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".
AFAIK it is the same, extention will be added if it absents.Rabah wrote: it seems that calling the .mo files directly is not the right solutionCode: Select all
m_locale.Addcatalog("message.mo")
I think it is redundant, quite enough work_dir/locale, because in m_locale.Init(lang), current lang was setted (fr_FR, f.e.).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)
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)
Yes it is.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
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10