您如何在无法重新启动的服务器(Apache)上使用 gettext?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2177895/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you use gettext on server (Apache) you can’t restart?
提问by Luc M
I asked this question on serverfaultbut I didn't get any response. I try here...
我在 serverfault 上问了这个问题,但没有得到任何回应。我在这里试试...
I developped a site on my web server at home.
我在家里的 Web 服务器上开发了一个站点。
When I modify the translation files, I have to restart the web server Apache.
当我修改翻译文件时,我必须重新启动 Web 服务器 Apache。
/etc/init.d/httpd graceful
Easy...
简单...
Suppose that my site is hosted on shared host.
假设我的网站托管在共享主机上。
Suppose now I need to modify the translation files.
假设现在我需要修改翻译文件。
I can't restart the server...
我无法重新启动服务器...
How do you use gettextin this context?
gettext在这种情况下如何使用?
Are you allow to restartthe server with the option graceful only?
您是否允许仅使用优雅选项重新启动服务器?
Does the share host restart the server once a day to resolve this kind of problem?
共享主机是否每天重启一次服务器来解决此类问题?
How do you work with such constraints?
你如何处理这些限制?
采纳答案by John Boker
the post here on the gettext function has some information for making gettext work without restarting apache:
这里关于 gettext 函数的帖子有一些信息,可以在不重新启动 apache 的情况下使 gettext 工作:
回答by Praveen D
call clearstatcache();
称呼 clearstatcache();
after making translation from *.poto *.mo
从做翻译后*.po到*.mo
回答by beggar
You can rename your *.mo file and your gettext domain to flush gettext cache without restarting apache server.But in production environment,it's unsuitable.
您可以重命名*.mo 文件和您的gettext 域以刷新gettext 缓存,而无需重新启动apache 服务器。但在生产环境中,这是不合适的。
回答by Szczepan Ho?yszewski
There is no other solution than to brutally forcea cache miss for each and every *.mo file every time one of them changes. Change a single string? New cache era!
没有其他解决方案,只能在每次 *.mo 文件中的一个更改时残酷地强制每个 *.mo 文件的缓存未命中。更改单个字符串?新的缓存时代!
I do this by writing middleware that copies all *.mo files to a timestamp-named directory (the timestamp being that of the newest *.mo file) and updates the application config with the new message path - if the newest timestamp actually changed, that is. Thus textdomains are now loaded from completely different paths, and thisis what finally manages to kill the stupid gettext cache stinking dead.
我通过编写中间件来将所有 *.mo 文件复制到一个时间戳命名的目录(时间戳是最新的 *.mo 文件的时间戳)并使用新的消息路径更新应用程序配置 - 如果最新的时间戳实际更改,那是。因此textdomains现在正在从完全不同的路径加载,这是什么终于设法杀害愚蠢的gettext缓存臭死人。

