The i18nActveRecord has been tested with Yii version 1.1.10 and should work with lower or higher versions as well. To use the i18nActiveRecord, the following changes should be done.

CActiveRecord class

i18nActiveRecord extends the CActiveRecord and uses some properties internally. In order for these properties to be accessible, we need to modify their access level.

The following properties access level should be changed from private to protected.

protected $_attributes;
protected $_related;
protected $_pk;

CSort class

In order for sorting to work with CGridView and CListView, the CSort method getOrderBy() should be modified a little.

    if(CActiveRecord::model($this->modelClass) instanceof i18nActiveRecord){
    else {

The only addition to the original code is

if(CActiveRecord::model($this->modelClass) instanceof i18nActiveRecord){

Common errors, reasons and solutions

Error Reason Solution
CException: Property "[AR].[property]" is not defined. You have not set the locale for the main object Set the locale for the i18n active record object by calling the setLocal() method.

Other issues

It is important to note that the following placeholder methods will not be called for the translation objects but will be called on the main object.

  • beforeValidate and afterValidate: these are invoked before and after validation is performed.
  • beforeSave and afterSave: these are invoked before and after saving an AR instance.
  • beforeDelete and afterDelete: these are invoked before and after an AR instance is deleted.
  • beforeFind: this is invoked before an AR nder is used to perform a query (e.g. find(), findAll()).
  • afterFind: this is invoked after every AR instance created as a result of query.