PHP - 如何将网站翻译成多种语言?
我有一个目前是英文的网站;当用户单击不同的语言时,我希望能够切换到不同的语言(网站上几乎没有国家标志图标).我目前正在尝试的方式是使用数组,例如:
I have a website that's currently in English; I want to be able to switch to a different language when a user clicks on a different language (there are little country flag icons on the site). The way I'm currently trying is with arrays, e.g.:
$english = array('index',
array('h1' => 'this is some h1 text',
'h2' => 'this is some h2 text'));
$japanese = array('index',
array('h1' => '世界交換への歓迎',
'h2' => 世界交換への'));
print $english[index][h1];
print $japanese[index][h2];
如您所见,如果我以单独的语言为每个页面都这样做,那将是大量的代码.我还可以尝试什么其他方法?
As you can see, if I did this for every single page in a separate language, it would be an insane amount of code. What other method can I try?
推荐答案
鉴于您正在寻找最终将导致 l10n 支持的完整 i18n 支持,我建议您在支持这些内容的 PHP 框架中编写您的页面盒子.
Given that you are looking for full i18n support which will eventually lead to l10n support, I would suggest writing your page in a PHP framework that supports these things out of the box.
就我个人而言,我只使用 Symfony 框架进行过翻译.他们将数据库中的 i18n 表扩展名组合用于内容,并将 XLIFF 文件用于界面翻译.它在设置后相当透明,并且使用框架避免了手动编写所有这些支持.
Personally I've only done translations with the Symfony framework. They use a combination of i18n table extension in the DB for content, and XLIFF files for translations of the interface. It was fairly transparent once it was setup, and using a framework avoids having to write all this support by hand.
我也知道 Zend、CakePHP 和 Code Igniter 都支持 i18n.
I also know that i18n is supported in Zend, CakePHP, and Code Igniter.
相关文章