Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gettext .po files under version control

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?

like image 481
Rene Saarsoo Avatar asked Jan 05 '10 13:01

Rene Saarsoo


People also ask

How do I open a .po file?

To open PO and POT files, you can use any text editor that supports the format (such as Notepad, Sublime Text, or Notepad++), use specialized software (like Poedit), or Localazy - the online translation management system explicitly made for working with translation file formats.

What are .po files?

A . PO file is a portable object file, which is text-based. These types of files are used in commonly in software development. The . PO file may be referenced by Java programs, GNU gettext, or other software programs as a properties file.

How do you translate PO files?

Translating PO and POT files is simple with Localazy. Sign up for free, create a new translation project and upload your PO, or POT file. Head to the Translations tab to add new languages and start translating. Localazy gives you a clean UI for translating PO and POT files.


1 Answers

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:

myVersionControl diff REV1 REV2 filea | grep -v '^..#' 

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 gitattributes and search for Performing text diffs of binary files. Here's the body of a sample script to save as /usr/local/bin/strippocomments which will do that:

grep -v '^#:' $1 

You can then tell git to use this script to preprocess po files, by adding the following to the file .git/info/attributes in your repository:

*.po diff=podiff 

and to the file .git/config in your repository:

[diff "podiff"]     textconv = /usr/local/bin/strippocomments 

Using git diff should then not include any lines starting with #:.

Note that the diffs generated from git diff using this approach should not be used for patching - but git format-patch will still use the default diff, so patches generated for emailing will still be ok.

like image 148
Alex Brown Avatar answered Oct 08 '22 22:10

Alex Brown