有一个小问题的瓶web应用程序。现在,我正在为一个网站创建后端,任务之一是在Flask中创建翻译面板。网站正在使用的多语言支持的瓶-Babel。
长话短说,我在Admin面板中制作了BaseView,它显示所有的翻译并提供编辑它们的能力。但是,在服务器启动时,Babel读取.mo文件还有一个问题,当我的View通过解析.po文件保存翻译并将它们编译到.mo文件网站时,在重新加载之前不会显示任何更新。
有什么办法解决这个问题吗。也许是巴贝尔以外的其他模块?
P.S.:当管理员单击“保存更改”视图时,我考虑(并尝试)重新加载网站,但这看起来是个愚蠢的主意,因为网站上的人可能正在做一些事情,而网站重新加载会删除他们的数据:(
发布于 2022-10-21 07:47:47
使用Flask (0.9.4),目录在域类的第一个转换过程中用get_translations函数加载到缓存中。
def get_translations(self):
"""Returns the correct gettext translations that should be used for
this request. This will never fail and return a dummy translation
object if used outside of the request or if a translation cannot be
found.
"""
ctx = _request_ctx_stack.top
if ctx is None:
return NullTranslations()
locale = get_locale()
cache = self.get_translations_cache(ctx)
translations = cache.get(str(locale))
if translations is None:
dirname = self.get_translations_path(ctx)
translations = support.Translations.load(dirname,
locale,
domain=self.domain)
cache[str(locale)] = translations
return translations缓存可以手动设置,即使它实际上是受保护的成员。假设您已经在您的应用程序中启动了作为babel的烧瓶-babelex。然后,您可以执行以下操作
from app import babel
babel._default_domain.cache = dict()之后,缓存将为空,并将在下一次翻译时再次保存。
用瓶1.1.4和瓶-babelex 0.9.4测试
https://stackoverflow.com/questions/63190560
复制相似问题