Currently using Gettext on a project and the .po files are nicely kept
under version control.
PO files of course contain translations, but in addition to that they
also contain some metadata – information about the exact files and
line numbers where the translatable strings are located.
The problem is that each time you update the PO files the metadata
changes a whole lot more than the actual translations. This makes it
really hard to later see from version control diff what actually was
changed – you just see a myriad of changes to file names and line
numbers. Like that:
- #: somefile.js:43
- #: somefile.js:45
- #: somefile.js:118
+ #: somefile.js:203
+ #: somefile.js:215
msgid "Translate me please"
msgstr "Tõlgi mind palun"
- #: somefile.js:23
- #: somefile.js:135
+ #: otherfile.js:23
+ #: otherfile.js:135
msgid "Note"
msgstr "Märkus"
- #: andThatFile.js:18
#: orThisFile.js:131
- msgid "Before I was like this"
- msgstr "Selline olin ma enne"
+ msgid "I happen to be changed"
+ msgstr "Paistab, et mind muudeti"
Of course, a simple fix would be to just disable the generation of
filename/linenumber comments in xgettext output. But I actually find
those file names to be quite useful hints when translating.
I surely cannot be the only one who doesn’t like the diffs of his PO files.
Suggestions?
A simple fix would be to apply a grep filter to remove comment metadata from the viewed diff. You can either do this to the output of the version control diff utility:
or you may be able to instruct the version control diff utility to ignore these before it makes the comparison, which will likely result in a more reliable and prettier output:
I don’t know what version control system you use, but git (for example) allows you to preprocess the input to diff and remove the comment lines for certain file types (thanks VonC), see
man gitattributesand search for Performing text diffs of binary files. Here’s the body of a sample script to save as/usr/local/bin/strippocommentswhich will do that:You can then tell git to use this script to preprocess po files, by adding the following to the file
.git/info/attributesin your repository:and to the file
.git/configin your repository:Using git diff should then not include any lines starting with
#:.Note that the diffs generated from
git diffusing this approach should not be used for patching – butgit format-patchwill still use the default diff, so patches generated for emailing will still be ok.