8

I have a web application where I have several translations using gettext. But now I have done a major rewrite of the application and while most of the strings are the same, there are also quite a few that were changed significantly or removed.

I use xgettext to create the .po files and it's great to be able to find new strings in the code and add them to the .po files, but I don't see an option to remove strings that aren't found in the code.

Is there an automated way to remove the strings from the .po files that are no longer in the code?

Mark Chackerian
  • 21,866
  • 6
  • 108
  • 99
getSurreal
  • 347
  • 5
  • 10
  • 2
    It's not automated, but my work around is to run xgettext twice. The first run I use the parameter --no-location. The second run puts the location back on the files. Now the text strings that are no longer used do not have a location and can be easily identified for deletion. – getSurreal May 12 '12 at 18:11

2 Answers2

9

Supposing you have a fresh PO template file that contains only strings that should be in the final PO catalog in a file called messages.pot, and target PO catalog in messages.po, you can do this:

msgattrib --set-obsolete --ignore-file=messages.pot -o messages.po messages.po

This marks any obsolete strings. The --set-obsolete switch tells msgattrib to apply the obsolete flag to all strings in the target file, and --ignore-file tells it to ignore strings that appear in specified file (the PO template in our case).

If you also want to completely remove them, there's one more step:

msgattrib --no-obsolete -o messages.po messages.po

You can read more about msgattrib command here.

-1

Сan so

find . -name '*.po' -print0 | while read -d '' -r file; do msgattrib --output-file="$file" --no-obsolete "$file"; done
XNicON
  • 153
  • 1
  • 6