Gettext 缓存烦恼

发布于 2024-12-13 02:49:32 字数 368 浏览 0 评论 0原文

我目前正在努力解决 PHP 中的 gettext 问题。

Gettext使用缓存。这是一件好事,但是当我更新翻译时,我无法访问它们,这很烦人。

我读到,除了重新启动网络服务器之外,我们无法刷新缓存,这不是一个可行的解决方案。 其他人使用不同名称的 .mo 文件副本来强制再次加载它们。

第一个问题

我正在搜索 gettext 将文件缓存在内存中多长时间,以考虑我的应用程序在字符串出现之前等待该时间是否可以接受。但我找不到该信息...持续时间是无限的吗?

第二个问题

我无法想象像 gettext 这样受欢迎的项目还没有解决这个问题的解决方案。它是 PHP 特定的吗?

预先感谢您提供的答案。 问候。

I'm currently struggling with gettext in PHP.

Gettext use cache. That's a good thing, but when I update my translations, I can't access them, which is annoying.

I read we can't flush the cache apart from restarting the web server, which is not a viable solution.
Other people use copy of the .mo files with a different name to force them to be loaded again.

First question

I was searching for how long gettext caches the files in memory to consider whether it's acceptable for my application to wait that time before the strings appear. But I couldn't find that information... Is the duration infinite?

Second question

I can't imagine a such popular project as gettext hasn't come with a solution to overcome this problem. Is it PHP-specific?

Thanks in advance for the anwsers I will have.
Regards.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

执着的年纪 2024-12-20 02:49:33

php-gettext 使用流似乎有点过时了。上次我检查时,Wordpress 读取文件并将它们转换为数组......并不是很有效。

我仍然更喜欢使用 gnu gettext ,在我的情况下,我需要通过执行以下操作来重新启动 phpfpm:

service php5.6-fpm-sp restart 。

希望对其他人有用。

php-gettext works with streams seems a bit outdated. Worrdpress last time I checked reads the files and converts them to Arrays...not really effective.

I still prefer to use gnu gettext , in my case I needed to restart phpfpm by doing:

service php5.6-fpm-sp restart.

Hope is useful to someone else.

独守阴晴ぅ圆缺 2024-12-20 02:49:32

每个使用 gettext 的应用程序在运行时总是使用缓存,该文件可能在启动/首次使用时打开,然后存储在内存中直到关闭。 PHP 作为 apache 的一部分持续运行(通过 mod_php),而不是启动和关闭。

如果您使用 php-cgi,则不会出现此问题,因为 PHP 在需要时由 apache 启动。

Gettext 最初是为桌面应用程序开发的,而不是长期运行的服务器端应用程序,“系统管理员”无法控制停止和启动。您不会期望桌面应用程序在运行时发生变化。

Every app that uses gettext always uses the cache while the app is running, the file is probably opened at start-up/first use and then stored in memory until closed down. PHP is continually running as part of apache (via mod_php) rather than starting up and closing down.

If you use php-cgi it doesn't have this problem as PHP is started by apache when needed.

Gettext was originally developed for desktop apps, not long running server side applications that the "sysadmin" doesn't have control over stopping and starting. You wouldn't expect a desktop app to change while running it.

月亮邮递员 2024-12-20 02:49:32

出于同样的原因,我们选择不使用 PHP 内置的 gettext,而是使用 php-gettext。您会损失一些性能(我们无法衡量),但您拥有更好的灵活性。

For the same reason we've chosen not to use gettext built into PHP, but rather php-gettext. You will loose a bit of performance (nothing we could measure), but you have better flexibility.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文