Vestimir Markov Sat May 28 10:33:35 -0400 2011

Subject: phpactiverecord and i18n

How i18n with additional table with translated columns can be achieved in phpactiverecord?

Example table setup:

articles { id, created_at, is_active } and articles_i18n { article_id, lang_id, title, description, content }


Yoan B Sun May 29 16:24:26 -0400 2011

I've got something but it's homemade. I give you the idea and will let you implement it, I guess:

 1 class Article extends TranslatedModel {
 2     static $has_many = array(
 3         array('translations', 'class_name' => 'ArticleTranslation'),
 4     );
 5     static $translated_attributes = array(
 6         array('title'),
 7         array('description'),
 8         array('content'),
 9     );
10 }
11 class ArticleTranslation extends Model {
12     static $belongs_to = array(
13         array('article'),
14         array('language'),
15     );
16 }
17 
18 $article = new Article(array(
19     'title_en' => 'Title',
20     'title_fr' => 'Titre',
21     'title_de' => 'Titel',
22 ));
Vestimir Markov Mon May 30 04:53:47 -0400 2011

I have implemented my own ActiveRecord a while ago and there the i18n was handled by making instance of a different class and defining a boolean for language mirroring (for example if the french and english site local version has different number of articles based on current lang or the same with translations).

1 class Article extends ActiveRecord\ModelI18n {
2 protected $has_mirror = true;
3 }

This week I'll look at the code and try to implement/port the ModelI18n class.

Yoan B Mon May 30 05:00:06 -0400 2011

By hitting the quote link you'll see the original formatting of posts.

Martín Palombo Wed Jun 08 13:22:41 -0400 2011

Hi!

I am also working on this but I'm quite new to php-AR. Yoan, care to give some guidelines on your implementation? I will be working on this in the following days.

In my particular case, I'm using the whole locale (e.g. en_US) instead of just the language part.

Also, I would like to access the Article in your example in the following way.

1 $article->title->en_us
2 $article->content->fr_fr
3 ...

I think it could be a great contribution to the project!

(1-4/4)