dongnai5905 2010-03-23 02:12
浏览 41
已采纳

Yii:多语言网站 - 最佳实践

I find Yii great framework, and the example website created with yiic shell is a good point to start... however it doesn't cover the topic of multi-language websites, unfortunately. The docs covers the topic of translating short messages, but not keeping the multi-lingual content ...

I'm about to start working on a website which needs to be in at least two languages, and I'm wondering what is the best way to keep content for that ... The problem is that the content is mixed extensively with common elements (like embedded video files).

I need to avoid duplicating those commons ... so far I used to have an array of arrays containing texts (usually no more than 1-2 short paragraphs), then the view file was just rendering the text from an array.

Now I'd like to avoid keeping it in arrays (which requires some attention when putting double quotations " " and is inconvenient in general...).

So, what is the best way to keep those short paragraphs? Should I keep them in DB like (id | msg_id | language | content ) and then select them by msg_id & language? That still requires me to create some msg_id's and embed them into view file ...

Is there any recommended paradigm for which Yii has some solutions?

Thanks, m.

  • 写回答

4条回答 默认 最新

  • dpsx99068 2010-03-25 17:13
    关注

    A Yii application by default uses yii::t() method for translating text messages and there are 3 different types for message sources:

    1. CPhpMessageSource : Translations are stored as key-value pairs in a PHP array.
    2. CGettextMessageSource : Translations are stored as GNU Gettext files. (PO Files)
    3. CDbMessageSource : Message translations are stored in database tables.

    If i don't misunderstand, you are using classic arrays for translations. I recommend to you using GetText and PO files with Yii for translation operations.

    You can find lot of information about translation and i18n with yii in this official documentation page.

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

报告相同问题?

悬赏问题

  • ¥20 代码:Python随机森林反演生物量数据处理问题
  • ¥50 微信野豹球杆小程序数据
  • ¥15 Linux系统的命令行窗口回车变成了换行,无法执行命令了
  • ¥15 vb6.0调用ImageMagick进行图片转换问题
  • ¥15 安卓组件化工程引入Arouter报错there's no route matched path[/login/LoginActivity,如何解决?
  • ¥50 如何进行点云姿态调整优化
  • ¥20 关于c++的问题 如何用qt完成
  • ¥15 台达变频器MS300与伺服驱动器B3系列的抱闸与电路设计如何实现
  • ¥20 C++通过HICON获取argb像素数组
  • ¥15 如何利用支持向量机提高分类器正确率和筛选理想分类器