问题描述
我有一个目前使用英语的网站;我希望能够在用户单击另一种语言时切换到另一种语言(该站点上有很少的国家标志图标).我目前正在尝试的方法是使用数组,例如:
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?
推荐答案
鉴于您正在寻找对i18n的全面支持,最终将导致对l10n的支持,我建议您在支持这些功能的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.
这篇关于PHP-如何将网站翻译成多种语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!