Two Wrongs

(don't make a right)

Move Translations Between Django Apps

by ~kqr

I have the pleasure of dealing with translation (as part of i18n, internationalisation) in Django, which is actually not said with irony. For some reason, translation is for me the perfect mix of creativity, logic and tranquility.

What is not fun, though, is if you have made a lot of translations in one app, and then move a bunch of the translated things to another app, because that seems like it would mean a lot of mindless copying of translations. There is no way to tell Django makemessages to "Generate a new translation file, but use this existing file as a guide when you encounter new strings."

Not Ideal, but It Works

What I have ended up doing is the following:

If I want to move translations from app A to app B, I append the .po file from app A to app B and run makemessages in both apps.

Since the app B .po file contains all translations from app A, makemessages will use them when generation the new .po file. It will also contain a bunch of translations that belong in app B, which end up in the new .po file as commented out "unused" translations at the bottom of the file. I just remove those.

The new .po file in app A will also contain a bunch of commented out "unused" translations (which are now part of app B!), which I remove.

It's kind of a long way around, and if you have unused translations you want to keep it still requires manual filtering when you remove unused translations, but at least that's a slightly easier process than finding and copying the relevant translations.

If you enjoyed this article, you might like others tagged with