jpfuentes2 / php-activerecord

ActiveRecord implementation for PHP
http://www.phpactiverecord.org/
Other
1.32k stars 443 forks source link

[Request] Translatable Trait / Model i81n #526

Closed adrianug closed 8 years ago

adrianug commented 8 years ago

I'm looking for the best way to work in multi-language website


class Language extends ActiveRecord\Model {
    static $table_name = 'web_language';
}

class Page extends ActiveRecord\Model {
    static $table_name = 'web_page';

    static $has_many = array(
        array('translation')
    );
}

class Translation extends ActiveRecord\Model {
    static $table_name = 'web_page_translation';

    static $belongs_to = array(
        array('page'),
        array('language')
    );
}

A little complex to retrieving and storing, i want to write less code, like $page = Page::find(...); $page->translate('en')->name; // hallo and $page = Page::find(...); $page->translate('fr')->name; // bonjour

koenpunt commented 8 years ago

I used php ar in a similar way for translations, and never been really satisfied. From what I've learned, translatable content is always complicated, especially when a cms and end-users come into play (should images be the same on all languages, are all languages populated, should it fallback).

So for me there hasn't been a true solution just yet..

jpfuentes2 commented 8 years ago

I'm going to echo @koenpunt's comment here: I don't think there's a single, comprehensive solution to il8n that would appease all users. I don't think it's the purpose of this library to offer such support; your application/product's needs will drive the implementation for il8n.

One further comment: in your example, I think it would be best to pass your models thru to a view presenter/decorator which manages il8n rather than adding this feature to AR itself.