getSurreal
getSurreal

Reputation: 377

How to automatically remove unused gettext strings?

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?

Upvotes: 8

Views: 3128

Answers (2)

user234932
user234932

Reputation:

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.

Upvotes: 10

XNicON
XNicON

Reputation: 183

Сan so

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

Upvotes: -1

Related Questions