简体   繁体   English

Gettext(i18n)和Smarty运行不稳定

[英]Gettext (i18n) and Smarty running erraticly

I'm developing a webapp with PHP and Smarty. 我正在用PHP和Smarty开发一个webapp。 I use gettext to internationalize, but I've a problem: it only works sometimes, absolutly randomly. 我使用gettext进行国际化,但是我有一个问题:它有时只能随机地绝对有效。 I load a locale ('de_DE', by example) with putenv+setlocale+bindtextdomain+textdomain, reload the page, and see "Search"; 我使用putenv + setlocale + bindtextdomain + textdomain加载语言环境(例如“ de_DE”),重新加载页面,然后看到“搜索”; reload again and I see "Suche"; 重新加载,我看到“搜索”; two more reloads and get "Suche" but thirth give me "Search" again, then I see "Search" many time and suddenly I can see "Suche" again... randomly. 再加载两次并获得“搜索”,但是渴了又给了我“搜索”,然后我多次看到“搜索”,然后突然我又可以随机地看到“搜索”了。

I've deactivated cache for Smarty, but same issue. 我已经停用了Smarty的缓存,但存在同样的问题。 I've configured Smarty to use different directories for different languages, templates_c/en_GB, templates_c/de_DE, and so on. 我已经将Smarty配置为对不同的语言使用不同的目录,templates_c / en_GB,templates_c / de_DE等。 Compiling works fine that manner. 编译可以通过这种方式很好地工作。

I'm using smarty-gettext for templates translation. 我正在使用smarty-gettext进行模板翻译。

Are there any known issue about using gettext and Smarty? 关于使用gettext和Smarty是否存在任何已知问题?

Edit to add some information: I'm running my tests in a Linux machine: 编辑以添加一些信息:我正在Linux机器上运行测试:

apache2 2.2.14 apache2 2.2.14

gettext 0.17 gettext 0.17

php 5.3.2 PHP 5.3.2

smarty 3-SVN$Rev: 3286 聪明的3-SVN $ Rev:3286

Do you have Xcache or any other opcode cacher installed/enabled? 您是否已安装/启用Xcache或任何其他操作码缓存器? Try disabling them. 尝试禁用它们。

I'm experiencing the same issue - sometimes the page shows the translation, and sometimes it doesn't. 我遇到了同样的问题-有时页面显示翻译,有时却没有。

But I'm using vanilla PHP (no Smarty), and running on Mac OS X (not Linux). 但是我使用的是普通PHP(没有Smarty),并且在Mac OS X(不是Linux)上运行。

My code looks like: 我的代码如下:

$locale='fr_FR'; //...for example...
putenv("LC_ALL=$locale");
setlocale(LC_ALL,$locale);
bindtextdomain("messages","./locale");
bind_textdomain_codeset("messages","UTF-8");
textdomain("messages");

Currently trying to hunt the problem down - I will let you know if I succeed. 目前正在设法解决问题-如果成功,我会通知您。

I had a similar intermittent problem PHP gettext and vagrant running ubuntu 我在运行ubuntu时遇到了类似的间歇性问题PHP gettext和vagrant

Try one of the following, I think it will depend how you have PHP running with Apache 请尝试以下方法之一,我认为这将取决于您如何在Apache上运行PHP

sudo service php5-fpm restart

sudo service apache2 restart

Used to get similar problem while using locale "pt_BR" when actually using russian words. 实际使用俄语单词时,使用区域设置“ pt_BR”时曾遇到类似的问题。 Solved this by setting locale to "ru_RU". 通过将语言环境设置为“ ru_RU”来解决此问题。 Hope this might help. 希望这会有所帮助。

This is my configuration that actually worked: 这是我的实际工作配置:

$directory = './locale';
$domain = 'smartybook';
$locale ="ru_RU";
setlocale(LC_ALL, $locale);
bindtextdomain($domain, $directory);
textdomain($domain);
bind_textdomain_codeset($domain, 'UTF-8');

One more important note: started working only after using msgfmt -c -v -o msgfmt -o wasn't enough. 还有一个重要的注意事项:仅在使用msgfmt -c -v -o msgfmt -o之后才开始工作。 Also important: need to be root when issuing formatting commands, also don't forget to restart apache. 同样重要:发出格式命令时必须是root用户,也不要忘记重新启动apache。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM