我们正在为翻译人员开发 .po 文件编辑器。翻译人员需要在实时网站上看到他们所做的更改。
我们设法为当前进程/线程重新加载 .mo 文件。但不是每个进程/线程。
是否有可能在不出现更大的性能问题的情况下实现这一点?
最佳答案
我们遇到了同样的问题。用户必须直接在网站上编写翻译。我找到了 django 1.1 的中间件,即清除翻译缓存并尝试在 django 1.4 中使用它。 顺序:
- 用户提交翻译
- 方法解析表单数据并修改*.po
- -subrocess.Popen(["python", "manage.py", "compilemessages"], stderr=PIPE, stdout=PIPE)(编译更改*.po)
清除缓存的函数
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/