9

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 text domain and puts everything in single file.

Sergey Stolyarov
  • 2,587
  • 3
  • 27
  • 40
  • I found a [suggestion](http://stackoverflow.com/a/5354360/645186) on how to parse each domain separately. However, this is a workaround. – Shef Mar 31 '12 at 09:54

2 Answers2

3

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.

Johan Dahlin
  • 25,300
  • 6
  • 40
  • 55
  • I already knew this solution, as mentioned in the comments of the question, but thanks for the effort. – Shef Apr 05 '12 at 07:31
  • If you think that's a workaround I don't think there'll be any solutions to the problem that are non-workarounds. The alternative would be to write your own program that extracts the dgettext() calls, but then you'd pretty much duplicate all the logic of xgettext. – Johan Dahlin Apr 05 '12 at 20:40
  • 1
    This is not a solution, but I am going to award the bounty to you, because it will be wasted otherwise. – Shef Apr 07 '12 at 06:47
0

If you are using linux, use gtranslator program to manipulate *.po and test your *.po files.

PersianGulf
  • 2,845
  • 6
  • 47
  • 67