douguwo2275 2009-03-27 19: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 20:06
    关注

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

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

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路