gettext: extract dgettext() strings to domain.po files
I have program with multiple domains, some source files contain dgettext() calls with different text domains.
How to extract gettext-strings to multiple .po files? For example, call dgettext('one', 'Hello')
should go to one.po, and dgettext('two', 'Bye')
to two.po. xgettext just ignores te开发者_Go百科xt domain and puts everything in single file.
First you need a way of separating the domains.
For instance, let's say you have a domain for lib and one for app, then create a shortcut for the dgettext()
call;
_app(msg) -> dgettext("app", msg);
and one for the lib domain:
_lib(msg) -> dgettext("lib", msg);
Add these calls all over your code, like this;
show_message(_app("Choose a directory to save your work."));
show_message(_lib("No space left on device."));
Remember that you need to call bindtextdomain()
for both domains when initializing your application.
To extract them you need to specify different keywords to xgettext
on all the filenames in your source tree that contains these markers:
xgettext --keyword=_app -d domain1 filenames...
xgettext --keyword=_lib -d domain2 filenames...
Finally, compile both of the .po files into their binary .mo variant and copy/install them to the right location.
If you are using linux, use gtranslator program to manipulate *.po and test your *.po files.
精彩评论