8

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.

Community
  • 1
  • 1
sleske
  • 81,358
  • 34
  • 189
  • 227
  • 1
    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 http://stackoverflow.com/a/3798064/179583 seems to apply to this just as well. – natevw Sep 26 '14 at 21:20

2 Answers2

2

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

  • 1
    Yes, using search-and-replace is the other obvious solution (together with dsas' solution of using fixed msgids). However, search-and-replace can get very complex, if some msgids are substrings of others, or also occur as part of translations, of if you need to duplicate msgids (original string used in multiple places, and only some change). So it's not a general solution. – sleske May 10 '12 at 09:41
2

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.

dsas
  • 1,650
  • 18
  • 30
  • This results in more work in the end. You edit the `.po` file for the original language, and then at some later point you inevitably have to get these changes back into the source files. And after that you again have the fuzzy entries that you wanted to avoid in the other language files. – Guido Flohr Aug 27 '18 at 05:47