reloading .mo files for all processes/threads in django without a restart

django, python

Solution

We had the same problem. Users must write translations direct on website. I've found middleware for django 1.1, that clear translation cache and try to use it in view with django 1.4. order:

- user submit from with translation

- methods parse form data and change *.po

- -subrocess.Popen(["python", "manage.py", "compilemessages"], stderr=PIPE, stdout=PIPE) (to compile changed *.po)

function below to clear cache

from django.utils import translation
from django.utils.translation import trans_real, get_language
from django.conf import settings
import gettext

if settings.USE_I18N:

    try:

        # Reset gettext.GNUTranslation cache.
        gettext._translations = {}

        # Reset Django by-language translation cache.
       trans_real._translations = {}

    # Delete Django current language translation cache.
    trans_real._default = None

    # Delete translation cache for the current thread,
    # and re-activate the currently selected language (if any)
    translation.activate(get_language())
except AttributeError:
    pass

Problem

We are working on a .po file editor for translators. And the translators need to see the changes they are doing on the live website. We managed to reload the .mo files for the current process/thread. but not for every process/thread. Is there a possibility to accomplish this without bigger performance problems?

Original source