xgettext --join-existing resulting multiple comments in my pot file

1.1k views Asked by At

I've a build script that scan source dir (PHP) and execute the xgettext --join-existing ... for updated translation and save into a pot file, e.g.

find . -type f -name '*.php' -not -path './vendor/*' | 
xargs xgettext --join-existing --keyword=_e --keyword=_x 
--keyword=__ --from-code=UTF-8 --default-domain=myapp 
--output=languages/myapp/myapp.pot

I don't know why, after several times of code refactoring and building, the pot file will have something like this

#: src/Member/Auth.php:196
#: src/Member/Auth.php:135
msgid "Login failed!"
msgstr ""
  1. Why there are two lines of source/line in the comment? (I guess it was due to we've moved the message around in the source.)

  2. So, how to make the xgettext ignore if the same file has updated content?

  3. Or should I not recommend to use --join-existing in the build script? (But sometimes we have manual item in the pot file, so how to solve?)

2

There are 2 answers

0
Henrik On

Sounds logically that xgettext appends information (even source reference), because it is explicitly set with the option --join-existing. But following workarounds could help.


Workaround 1

Remove previous source references from the pot file with sed before building the new pot:

sed -i.old '/^#: /d' languages/myapp/myapp.pot

Workaround 2

Do not use the option --join-existing and place the manual items in a dummy php file.

0
Maug Lee On

Would here be a problem if using poedit? It is GUI application with „Update“ button. Poedit scans all files and collects all translatable strings. I have used it a lot for a long time and it does its job perfect.