douguwo2275 2009-03-27 11:40
浏览 102
已采纳

如何使用多语言支持构建PHP应用程序(英语,法语,中文等..)

I'm building a web application that uses LAMP and the Smarty template framework. The website will have plenty of static content (about us page, error alerts, confirmation emails etc...).

The web application must support multiple languages. Is the following approach appropriate?

1) All static copy on Smarty template pages (html pages) will be replaced by calls to smarty plugins such as {lang file='about.xml' getTerm='title'} which returns a string for the title tag in the appropriate language

2) The file about.xml is an xml document on the webserver that acts as a multiple language dictionary. So it will have xml nodes such as

<term value="title">
   <en>&lt;a href=&quot;http://stackoverflow.com&quot;&rt;Stackoverflow&lt;/a&rt; is a great site</en>
   <fr>&lt;a href=&quot;http://stackoverflow.com&quot;&rt;Stackoverflow&lt;/a&rt; c'est website magnifique</fr>
   <ch>&lt;a href=&quot;http://stackoverflow.com&quot;&rt;Stackoverflow&lt;/a&rt; complex looking chinese characters I don't udnerstand</ch>
</term>
<term value="signupmessage">
   <en>&lt;a href=&quot;http://stackoverflow.com&quot;&rt;Stackoverflow&lt;/a&rt; great deals!</en>
   <fr>&lt;a href=&quot;http://stackoverflow.com&quot;&rt;Stackoverflow&lt;/a&rt; magnifique deals!</fr>
   <ch>&lt;a href=&quot;http://stackoverflow.com&quot;&rt;Stackoverflow&lt;/a&rt; complex looking chinese characters I don't udnerstand</ch>
</term>

3) The url structure for the site will be http://mywebsite.com/language/index.php. To do this, my webserver will have symbolic links such as ln -s ./en ./ so that http://mywebsite.com/en/index.php points to the same php page as http://mywebsite.com/fr/index.php, but I will check the url for language settings. My hope is that google will index both versions of the site.

Is this a good approach? Is xml the best format for storing content of different languages even though it has htmlentity encoded html tags? Did I overlook anything?

  • 写回答

2条回答 默认 最新

  • douyin8623 2009-03-27 12:06
    关注

    Not sure about the details of your question but you may want to take a look at Zend_Translate.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部