views:

960

answers:

4

Hi, 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.

+1  A: 

Hi, maybe this helps;

A Yii application by default uses yii::t() method for translating text messages and Yii has a 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.

Edigu
+1  A: 

Have look at FlexciaCMS. They have plan to support multi-language content and their model looks good.

Pokamy
A: 

Well I think what is concerned here is how to translate static text/messages on the page and Yii solves it pretty well using Yii:t() and Edigu's answer is for it.

I check out the post on FlexicaCMS about translating dynamic content in database, well ultimately that will be the next after you solve static text/message problem, and that is a truly good approach using Yii's behavior. Not sure if FlexicaCMS authors are too ambitious in supporting translation that way as it would make content translation a worry-free thing - really great.

One thing they don't mention is the url of translated page. For example your.site.com/fr/translated_article_title.html. I mean the url must has /language_id/ part in it so it can help with SEO.

A: 

@richie_thai: This could be the multi-lingual and url thing that you are talking about.

Pokamy