Is there an build-in method to have multiple languages in database? I have to build a website with more than one language, and I would like to know, how to handle this in databse table. I.e. i have a table with a column strName, so do I have to make a column strNameDe and a column strNameEn and in and view file something like this:
Ok, l'll have to take a look at this, but it's not quite cleat how I can use this for example when a have I a product table, and want to store product names in german and english.
I've just asked for a build-in solution, because "Symfony" has got one.
It's still not clear to me how I can handle the following scenario:
I have a table called "Products" and in the _form.php of products I have two input fields (there are a lot of more):
strProductNameEn
strProductNameDe
Can I use CDbMessageSource to save the product names (english and german) in database with having the multi-langual values in a separate table, with only one column in table "Products" for strProductName or does the "Products" table needs to have two columns, to hold multi-lingual values of a model (which doesn't require an extra table)?
Other fields of the model are i.e. strProductExcerpt(En/De), strProductDescription(En/De).
is there something built in that resembles a translate behavior where you have a translated fields table used as a repository for all the fields you need translated ? The translation table has the following fields :
locale (language)
model (like Post, Comment, Product etc … )
foreign_key (the id of the row in foreign table)
field (the field in the row that has to be translated)
thank you for the reply, but I think that's not what I'm looking for. I don't want to store the translation coming from php code in the database! what I want to do is, to handle multi-language columns in all tables
oh I see… I’ve misunderstood your post
anyway the question you made is interesting for mee too… so please let me know wich will be your solution
hope that anyway you'll find my tool useful as you are going to work with multiple language (I do prefer to store strings in db rather than in text files but this is another topic) … anyway just for say that I believe that Yii is very powerfull in handling multi language projects but since now I didn't saw many projects that are using this features in a heavy way.
And also didn’t knew about that cake php feature that looks useful The Yii dev. team is very open to this kind of improvements according to what I saw… so I believe that version 1.1 will be awesome.
@giovanni: I made a feature request, because I need this feature for 3 projects in the near future, and I don't know how to handle this without Yii having this feature built-in.
Bitmatix, I have the exact need for this. I think there is a solution already. The Doc system is very similar to what we need. You click any language icon and you see the same chapter in that language. I am not sure how much coding was included there but I assume it should be pretty light.
Ok, I've found a way to handle this with attached behaviors. The onyl problem is, that the "fake" translation fields have to added manually in the model, i.e. if your main language is german and you have a field called "strName" which should be translated into english, you have to add:
public $strNameEn;
and the in rules() function:
public function rules()
{
return array(
array('strName','length','max'=>255),
array('strNameEn','length','max'=>255),
array('strName, strNameEn', 'required'),
);
}
you also have to add the safeAttributes function with something like that:
public function safeAttributes()
{
return CArray::merge($this->attributeNames(), array('strNameEn'));
}
I hope to get this things a little bit more dynamically, but actually I don't know how!? Maybe there's some help or inspiration from the Yii developers
the rest (reading and writing the translated values) is done by the behavior class.