You must first sign up to be able to contribute.

= How To Handle i18n Db Fields With the Admin Generator Data Recovery Services=

Notice: for symfony 1.2 read HowToHandlei18nDbFieldsWithAdminGenerator1.2

You can manage i18n fields in the backend generated by the admin generator this way.

Imagine you got a schema like this for managing i18n categories :

  <table name="categories" isI18N="true" i18nTable="categories_i18n" baseClass="i18nBaseClass" phpName="Category">
    <column name="id" type="INTEGER" primaryKey="true" required="true" autoIncrement="true"/>
    <column name="name" type="VARCHAR" size="255" required="true"/>
    <column name="is_active" type="BOOLEAN"/>
  <table name="categories_i18n" phpName="CategoryI18n">
    <column name="id" type="INTEGER" primaryKey="true" required="true"/>
    <column name="culture" isCulture="true" type="CHAR" size="3" primaryKey="true" required="true"/>
    <column name="title" type="VARCHAR" size="255" required="true"/>
    <column name="excerpt" type="LONGVARCHAR"/>
    <column name="description" type="LONGVARCHAR"/>
    <foreign-key foreignTable="categories">
      <reference local="id" foreign="id"/>

Did you notice our Category model extends the i18nBaseClass? All this class has is a constructor which adds the culture currently selected. This way, we're getting localized content in the edit and list actions without the need to override a bunch of methods:

class i18nBaseClass extends BaseObject
  public function __construct()

Then we must enable the external i18n fiels, by enabling them in the generator.yml for the categories module:

  class:                sfPropelAdminGenerator
    model_class:        Category
    theme:              default

      display:          [=name, title, excerpt, description]

      display:          [name, title, excerpt, description]
        title:          { params: disabled=false }
        excerpt:        { params: disabled=false, params: size=100x2, type: textarea_tag }
        description:    { params: disabled=false, params: size=100x4, type: textarea_tag }

Specify a default culture in the app/config/i18n.yml file:

  default_culture:   en

Then, you'll probably want to add a lang chooser in your app/templates/layout.php, like this :

<div class="lang-area">
  <?php echo form_tag('utils/language') ?>
      <?php echo label_for('culture', __('Langue courante d\'├ędition des contenus').' :') ?><br/>
      <?php echo select_language_tag('culture', $sf_user->getCulture(), array('id' => 'culture')) ?>
      <?php echo submit_tag('Go') ?>

And - for our example - in the utils module, for the executeLanguage action:



  public function executeLanguage() {
    $this->setFlash('notice', 'New current session locale : '.$this->getUser()->getCulture());
    $url = $this->getRequest()->getReferer() != '' ? $this->getRequest()->getReferer() : '@homepage';