结合使用gettext和smarty最简单的方法是什么,有没有类似于php:_('hello world');的功能?
谢谢,
发布于 2012-11-30 08:32:26
我真的发现Smarty对(n)gettext的支持也非常缺乏。虽然现有的插件似乎做了一个公平的工作,我仍然认为我应该试一试。
我刚刚发布了:http://code.google.com/p/smarty-gettext/
也许这对任何人都有帮助。反馈,等等,非常感谢。
发布于 2011-10-06 21:50:35
看起来有一个smarty-gettext插件可用:http://sourceforge.net/projects/smarty-gettext/,最近一次更新于2011年5月。http://smarty.incutio.com/?page=SmartyGettext
发布于 2013-07-12 20:58:56
有很多方法可以用Smarty实现页面的翻译。
我的方式
我创建了一些.conf文件,其中包含以下内容:
en.conf
hello_world = "Hello! World!"
my_name_is = "They call me"nl.conf
hello_world = "Hallo! Wereld!"
my_name_is = "Ik heet"fr.conf
hello_world = "Bonjour! Tout le Monde!"
my_name_is = "Ils m'appellent"现在您有两个选项:
.tpl文件中加载.conf文件:template.tpl (英语)
{config_load file="en.conf"}
<html>
<body>
<h1>{#hello_world#}</h1>
<p>
{#my_name_is#}
</p>
</body>
</html>template.tpl (荷兰语)
{config_load file="nl.conf"}
<html>
<body>
<h1>{#hello_world#}</h1>
<p>
{#my_name_is#}
</p>
</body>
</html>template.php (在PHP中使用Smarty类)
$configFile = 'fr.conf';
// Smarty Version 2
$this->smarty->config_load($configFile);
//Smarty Version 3
$this->smarty->configLoad($configFile);我希望这对你也是有效的。
https://stackoverflow.com/questions/7675180
复制相似问题