Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I automatically update msgids in gettext's .po files for trivial text changes?

With gettext, the original (usually English) text of messages serves as the message key ("msgid") for the translations. This means that every time the original text changes, the msgid must be updated in all the .po files.

For real changes of the text, this is obviously unavoidable, as the translator must update the translation.

However, if the change of the original does not change its meaning, re-translation is superflous (e.g. change in punctation, whitespace changes, or correction of a spelling mistake).

Is there a way to update the .po files automatically in that case?

I tried to use xgettext & msgmerge (with fuzzy matching turned on), but fuzzy matching sometimes fails, plus this produces lots of ugly "#,fuzzy" flags.

Note: There is a similar question: How to efficiently work with gettext PO files when making small edits to large text values However, it's about large strings, thus about a more specific problem.

like image 439
sleske Avatar asked Nov 27 '11 18:11

sleske


2 Answers

One way to avoid the problem is to leave the msgids alone, have a .po file for the original language and make the fix inside that.

It always strikes me as being more of a work around than a proper fix though. For the next iteration (where there will definitely be more msgid changes) the msgid is changed and either the translators translate it in their usual update or each language is updated by hand when the msgid is changed.

like image 189
dsas Avatar answered Oct 18 '22 10:10

dsas


I've had exactly this issue when doing minor changes to a django project. What I do is the following:

  1. Change message in code.
  2. Run find and replace on all translation files ("django.po"), replacing the old message (msgid) with the new one.
  3. Run django-admin makemessages.

If I have done things right, the last step is superflous (i.e, you have done the change for gettext). django uses the gettext utilities, so it shouldn't matter how you make your message files.

I find and replace like so: find . -name "*.po" -print | xargs sed -i 's/oldmessageid/newmessageid/g' Courtesy of http://rushi.vishavadia.com/blog/find-replace-across-multiple-files-in-linux

like image 42
Guttorm Flatabø Avatar answered Oct 18 '22 10:10

Guttorm Flatabø