python - 在不重启的情况下为django中的所有进程/线程重新加载.mo文件

标签 python django

我们正在为翻译人员开发 .po 文件编辑器。翻译人员需要在实时网站上看到他们所做的更改。

我们设法为当前进程/线程重新加载 .mo 文件。但不是每个进程/线程。

是否有可能在不出现更大的性能问题的情况下实现这一点?

最佳答案

我们遇到了同样的问题。用户必须直接在网站上编写翻译。我找到了 django 1.1 的中间件,即清除翻译缓存并尝试在 django 1.4 中使用它。 顺序:

  1. 用户提交翻译
  2. 方法解析表单数据并修改*.po
  3. -subrocess.Popen(["python", "manage.py", "compilemessages"], stderr=PIPE, stdout=PIPE)(编译更改*.po)
  4. 清除缓存的函数

    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
    

关于python - 在不重启的情况下为django中的所有进程/线程重新加载.mo文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1392913/

相关文章:

c++ - 提升 python : how to call a C++ virtual function

python - 如何关闭 cherrypy 服务器?

python - django 命令找不到命令模块

python - 如何将 django 中的多个字段添加到一起?

python - 在 Pandas Dataframe Cell 中查找特定格式

python - Openerp中Lead的onclick无法获取自定义模块中Lead的详细信息

python - subprocess.call() 在 Mac 和 Linux 上失败

django - 我想在 django 模型中添加一个位置字段,通过放置纬度和经度来获取位置输入

python - 如何使用 Python/Django 应用程序发送短信?

django - django template.if语句中的URL名称