Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

django

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?

like image 655
digi604 Avatar asked Sep 08 '09 09:09

digi604


People also ask

Which of the following command is used to disable auto reloading of code while the development server is running?

Use the --noreload option to disable the use of the auto-reloader. This means any Python code changes you make while the server is running will not take effect if the particular Python modules have already been loaded into memory. The development server is multithreaded by default.

What is Gettext_lazy in Django?

gettext_lazy() In definitions like forms or models you should use gettext_lazy because the code of this definitions is only executed once (mostly on django's startup); gettext_lazy translates the strings in a lazy fashion, which means, eg.

How to translate in Django?

Overview. In order to make a Django project translatable, you have to add a minimal number of hooks to your Python code and templates. These hooks are called translation strings. They tell Django: “This text should be translated into the end user's language, if a translation for this text is available in that language. ...


1 Answers

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:

  1. user submit from with translation
  2. methods parse form data and change *.po
  3. -subrocess.Popen(["python", "manage.py", "compilemessages"], stderr=PIPE, stdout=PIPE) (to compile changed *.po)
  4. 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
    
like image 124
Andy Dreamer Avatar answered Oct 02 '22 07:10

Andy Dreamer