i18n - Show correct format in attribute form


I have developed the application with en_US source language (Yii 1.1.4).

My language target is es_es (date format: aa-mm-YYYY instead of YYYY-mm-aa; number format: ‘,’ is the decimal separator and ‘.’ is the thousand separator).

I have setup the main.php putting:


I use the CDateFormatter and CNumberFormatter to change the format of the variables and works fine. For example:


Well, my problem is when I try to change the format of the values if they are attributes of a model. I don’t know how to use the locate in this situation. For example to a date variable call “fecha”:



public function rules()


                // NOTE: you should only define rules for those attributes that

                // will receive user inputs.

                return array(

                        array('id_asociado, id_estado, fecha', 'required'),

                        array('id_asociado, id_estado', 'length', 'max'=>10),

                        array('fecha', 'type', 'type'=>'date' ,'dateFormat'=>Yii::app()->locale->dateFormat),

                        array('notas', 'safe'),

                        // The following rule is used by search().

                        // Please remove those attributes that should not be searched.

                        array('id_historial, id_asociado, id_estado, fecha, notas, timestamp', 'safe', 'on'=>'search'),





<div class="row">

                <div style="min-width: 150px; float: left">

                <?php echo $form->labelEx($model,'fecha'); ?> (DD/MM/AAAA)



                echo $form->textField($model,'fecha');



                <?php echo $form->error($model,'fecha'); ?>


Could I use anything to show "fecha" in the correct format depends of the locale used?

And, then automatic format conversion to save (from the form to database) to a model without use beforeSave function too? (Actually I’m using a beforeSave to change the format but this way doesn’t depend of the locale value).

I’m searching how to configure numeric and datetime model attributes that they have a automatic correct format depends of the locale value in main.php.

Is possible?

Thanks in advanced.

PD: Sorry for my english.

I supposed that the idea to implementation the solution is here.

Use a get/set function to convert the value of the attribute to target language (Locale) o to source language.

Source Language -> Target Language (Locale):


In the controller when you receive the $model and your attributes you can use the set function of the attribute to change the value. Then you pass the $model with your correct format.

This step works fine.

Target Language (Locale) -> Source Language:


You can use two ways:

1.- In the controller before to call DB functions (save, find…) you can alter the attributes in the model using set function of attributes.

2.- Using a behaviours on your models class (beforeSave,…) using the set function of attributes.

In this step you can’t configure a format source language. In the above issue the set function use a implicit format customize.

Is possible to implements a format source language functions/properties (including format to language DB engine) to allow easily and automatically use a indifferent source and target languages??