How can I compile a .po
file using xgettext with PHP files with a single command recursively?
My PHP files exist in a hierarchy, and the straight xgettext
command doesn't seem to dig down recursively.
How can I compile a .po
file using xgettext with PHP files with a single command recursively?
My PHP files exist in a hierarchy, and the straight xgettext
command doesn't seem to dig down recursively.
Here's a solution for Windows. At first, install gettext and find from the GnuWin32 tools collection.
You can run the following command afterwards:
The output file has to exist prior to running the command, so the new definitions can be merged with it.
Got it:
I was trying to use
-exec
before, but that would only run one file at a time. This runs them on the bunch.Yay Google!
This is the solution I found for recursive search on Mac:
Generates entries for all uses of method gettext in files whose extension is php, including subfolders and inserts them in translations/messages.pot .
For WINDOWS command line a simpe solution is:
You cannot achieve this with one single command. The xgettext option
--files-from
is your friend.If you are positive that you do not have too many source files you can also use
find
withxargs
:However, if you have too many source files,
xargs
will invokexgettext
multiple times so that the maximum command-line length of your platform is not exceeded. In order to protect yourself against that case you have to use the xgettext option-j
,--join-existing
, remove the stale messages file first, and start with an empty one so that xgettext does not bail out:Compare that with the simple solution given first with the list of source files in
POTFILES
!Using
find
with--exec
is very inefficient because it will invokexgettext -j
once for every source file to search for translatable strings. In the particular case ofxgettext -j
it is even more inefficient because xgettext has to read the evergrowing existing output filemessages.po
with every invocation (that is with every input source file).