6
votes

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.

2
Thanks for referencing the similar question; I'd agree that perhaps there are different answers and won't play at duplicate cop — however I will say that stackoverflow.com/a/3798064/179583 seems to apply to this just as well.natevw

2 Answers

2
votes

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.

2
votes

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