Yii Framework Forum: I18Nactiverecord - A Multilingual Active Record - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

I18Nactiverecord - A Multilingual Active Record

#1 User is offline   rontiki 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 21-March 11

Posted 05 October 2012 - 11:03 PM

The i18nActiveRecord is an Active Record for representing internationalized relational data in Yii. It extends the ActiveRecord class by providing an integrated translation capability. You can use it as you would use any CActiveRecord. I wouldn't want to write a whole lot here but you can read the full details on my blog.

Below is a snippet of what it can do.

create table item(
  id integer not null primary key auto_increment,
  price double(10,2) not null
create table item_i18n(
  i18n_id integer not null,
  locale varchar(4) not null,
  name varchar(128) not null,
  description text,
  primary key(i18n_id,locale)

$item = new Item();
$item->price = 2.99;

// add an English translation
$item->name ='Microwave oven';

// add a French translation
$item->name ='Four micro-ondes';

// save the item and its translations

// retrieve text and non-text translations directly from the main object
echo $item->price; // 12.99
echo $item->name; // Microwave oven
echo $item->name; // Four micro-ondes

    //both english and french translation will get new name
    $itemi18n->name= "New name";

$item = Item::model()->findByPk(1);
// remove the French translation

$items = Item::model()->findAll(); // one query to retrieve all items
$locale = 'en_US';
foreach ($items as $item) {
  echo $item->price;
  echo $item->name; // one query to retrieve the English translation

$items = Item::model()
  ->find(); // one query to retrieve both all items and their translations
foreach ($items as $item) {
  echo $item->price;
  echo $item->name; // no additional query

You can get detailed requirements also from there.

Share this topic:

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users