Commits

Anonymous committed 2c22595

  • Participants
  • Parent commits 90aaf00

Comments (0)

Files changed (10)

   private $_mostrarTodos = true;
   private $_showAll = true;
   private $_mostrarInactivos = true;
-  private $_mostrarDeactivated = true;
+  private $_showDeactivated = true;
+  private $_idiomaAux = '';
+  private $_langAux = '';
   private $_assetsUrl;
 
   public function init() {
 
   public function setMostrarInactivos($mostrarInactivos) {
     $this->_mostrarInactivos = eval("return $mostrarInactivos;");
+    $this->_showDeactivated = eval("return $mostrarInactivos;");
   }
 
   public function setShowDeactivated($showDeactivated) {
     return $this->_showDeactivated;
   }
   
+  public function setIdiomaAux($idiomaAux) {
+    $this->_idiomaAux = $idiomaAux;
+    $this->_langAux = $this->_idiomaAux;
+  }
+
+  public function setLangAux($idiomaAux) {
+    $this->setIdiomaAux($idiomaAux);
+  }
+  
+  public function getIdiomaAux() {
+    return $this->_idiomaAux;
+  }
+  
+  public function getLangAux() {
+    return $this->_langAux;
+  }
+
   /**
    * 
    * @return string Devuelve una cadena que debe evaluarse para mostrar el selector de Idiomas

components/MensajeATraducir.php

       $lastID = Yii::app()->db->lastInsertID;
     }
 
-    if ($event->language != Yii::app()->sourceLanguage) {
+    if ($event->language != Yii::app()->sourceLanguage
+            || $event->sender->forceTranslation) {
       // Hacemos lo mismo con las traducciones	
       $traduccion = MsgTraducido::model()->find('language=:idioma AND id=:id', 
                                                array(':idioma' => $event->language, 

controllers/MsgTraducidoController.php

 		));
 	}
 
-	/**
-	 * Updates a particular model.
-	 * If update is successful, the browser will be redirected to the 'view' page.
-	 * @param integer $id the ID of the model to be updated
-	 */
-  /* Original
-	public function actionUpdate($id)
-	{
-		$model=$this->loadModel($id);
-
-		// Uncomment the following line if AJAX validation is needed
-		// $this->performAjaxValidation($model);
-
-		if(isset($_POST['MsgTraducido']))
-		{
-			$model->attributes=$_POST['MsgTraducido'];
-			if($model->save())
-				$this->redirect(array('view','id'=>$model->id));
-		}
-
-		$this->render('update',array(
-			'model'=>$model,
-		));
-	}
-  */
-  /* Para eupdatedialog*/
   public function actionUpdate($id, $lng)
 {
   $model = $this->loadModel($id, $lng);
+ar,العربية,0,0000-00-00 00:00:00
+az,Azərbaycan,0,0000-00-00 00:00:00
+bg,Български,0,0000-00-00 00:00:00
+bs,Bosanski,0,0000-00-00 00:00:00
+ca,Català,0,0000-00-00 00:00:00
+cs,Česky,0,0000-00-00 00:00:00
+da,Dansk,0,0000-00-00 00:00:00
+de,Deutsch,0,0000-00-00 00:00:00
+el,Ελληνικά,0,0000-00-00 00:00:00
+en,English,0,0000-00-00 00:00:00
+es,Español,0,0000-00-00 00:00:00
+et,Eesti,0,0000-00-00 00:00:00
+fi,Suomi,0,0000-00-00 00:00:00
+fr,Français,0,0000-00-00 00:00:00
+he,עברית,0,0000-00-00 00:00:00
+hr,Hrvatski,0,0000-00-00 00:00:00
+hu,Magyar,0,0000-00-00 00:00:00
+hy,Հայերեն,0,0000-00-00 00:00:00
+is,Íslenska,0,0000-00-00 00:00:00
+it,Italiano,0,0000-00-00 00:00:00
+ja,日本語,0,0000-00-00 00:00:00
+ko,한국어,0,0000-00-00 00:00:00
+lt,Lietuvių,0,0000-00-00 00:00:00
+lv,Latviešu,0,0000-00-00 00:00:00
+mk,Makedonski,0,0000-00-00 00:00:00
+mn,Монгол,0,0000-00-00 00:00:00
+mt,Malti,0,0000-00-00 00:00:00
+nl,Nederlands,0,0000-00-00 00:00:00
+no,Norsk,0,0000-00-00 00:00:00
+pl,Polski,0,0000-00-00 00:00:00
+pt,Português,0,0000-00-00 00:00:00
+ro,Română,0,0000-00-00 00:00:00
+ru,Русский,0,0000-00-00 00:00:00
+sk,Slovenčina,0,0000-00-00 00:00:00
+sl,Slovenščina,0,0000-00-00 00:00:00
+sq,Shqip,0,0000-00-00 00:00:00
+sr,Српски / Srpski,0,0000-00-00 00:00:00
+sv,Svenska,0,0000-00-00 00:00:00
+sz,Crnogorski,0,0000-00-00 00:00:00
+th,ไทย,0,0000-00-00 00:00:00
+tr,Türkçe,0,0000-00-00 00:00:00
+uk,Українська,0,0000-00-00 00:00:00
+uz,O‘zbek,0,0000-00-00 00:00:00
+vi,Tiếng Việt,0,0000-00-00 00:00:00
+zh,中文,0,0000-00-00 00:00:00

models/Idioma.php

 
   public $tabla = 'tbl_idioma';
 
-
   /**
    * Returns the static model of the specified AR class.
    * @return Idioma the static model class
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 FIN;
       Yii::app()->db->createCommand($sql)->execute();
-      $sql = <<<FIN
-INSERT INTO `$this->tabla` (`idiCodigo`, `idiDescripcion`, `idiActivo`, `idiBaja`) VALUES
-('en', 'English', 0, NULL),
-('es', 'Español', -1, NULL);
-FIN;
-      Yii::app()->db->createCommand($sql)->execute();
     }
     /* Agregar aquí las subsecuentes modificaciones a esta/s tabla/s
      * y los procedimientos para actualizarlas
      */
+    //2013-01-04 Se agregan todos los registros de idioma de ISO 639-1
+    $sql = "SELECT COUNT(*) FROM $this->tabla;";
+    if (Yii::app()->db->createCommand($sql)->queryScalar() < 45) {
+      $sql = "LOAD DATA LOCAL INFILE '" . Yii::getPathOfAlias('gemi') . DIRECTORY_SEPARATOR . "idioma.csv' "
+              . "IGNORE "
+              . "INTO TABLE $this->tabla "
+              . "FIELDS TERMINATED BY ',' "
+              . "LINES TERMINATED BY '\n' "
+              . "(idiCodigo, idiDescripcion, idiActivo, idiBaja);";
+      Yii::app()->db->createCommand($sql)->execute();
+    }
+    //Si la tabla no existía, se "ajustan" los registros de idioma según sourceLanguage e idiomaAux
+    if (!$tbl_existe) {
+      $sourceLanguage = Yii::app()->sourceLanguage;
+      $idiomaAux = Yii::app()->getModule('gemi')->idiomaAux;
+      $sql = <<<FIN
+UPDATE `$this->tabla` SET `idiBaja`= NULL WHERE `idiCodigo` = '$idiomaAux';
+FIN;
+      Yii::app()->db->createCommand($sql)->execute();
+      $sql = <<<FIN
+UPDATE `$this->tabla` SET `idiActivo`=-1, `idiBaja`= NULL WHERE `idiCodigo` = '$sourceLanguage';
+FIN;
+      Yii::app()->db->createCommand($sql)->execute();
+    }
   }
 
   public function titulo($i = 0) {
     // NOTE: you may need to adjust the relation name and the related
     // class name for the relations automatically generated below.
     return array(
-        'tblArticulos' => array(self::MANY_MANY, 'Articulo', 'tbl_artdescripcion(artCodigo, idiCodigo)'),
-        'colors' => array(self::HAS_MANY, 'Color', 'idiCodigo'),
-        'grupos' => array(self::HAS_MANY, 'Grupo', 'idiCodigo'),
-        'listaprecios' => array(self::HAS_MANY, 'Listaprecio', 'idiCodigo'),
-        'materials' => array(self::HAS_MANY, 'Material', 'idiCodigo'),
     );
   }
 
     $lng = substr(Yii::app()->request->preferredLanguage, 0, strpos(Yii::app()->request->preferredLanguage, "_"));
     if ($this->IdiomaEstaDisponible($lng))
       return $lng;
+    else if ($this->IdiomaEstaDisponible(Yii::app()->getModule('gemi')->idiomaAux))
+      return Yii::app()->getModule('gemi')->idiomaAux;
     else
       return Yii::app()->sourceLanguage;
   }
       $aLista[$aRegistro->idiCodigo] = $aRegistro->idiDescripcion;
     }
     return $aLista;
-  
   }
 
   public function getMostrarSelector() {

models/MsgTraducido.php

  * @property Idioma $language0
  * @property MsgOriginal $message
  */
-class MsgTraducido extends CActiveRecord
-{
+class MsgTraducido extends CActiveRecord {
+
   public $tabla = 'tbl_msgTraducido';
   public $message;
   public $category;
-  
-	/**
-	 * Returns the static model of the specified AR class.
-	 * @return MsgTraducido the static model class
-	 */
-	public static function model($className=__CLASS__)
-	{
-		return parent::model($className);
-	}
 
-	/**
-	 * @return string the associated database table name
-	 */
-	public function tableName()
-	{
+  /**
+   * Returns the static model of the specified AR class.
+   * @return MsgTraducido the static model class
+   */
+  public static function model($className = __CLASS__) {
+    return parent::model($className);
+  }
+
+  /**
+   * @return string the associated database table name
+   */
+  public function tableName() {
     $this->verificarTabla();
-		return $this->tabla;
-	}
+    return $this->tabla;
+  }
 
   public function verificarTabla() {
     /* Versión Original
     // return array('pk1', 'pk2');
   }
 
-  public function titulo($i=0){
+  public function titulo($i = 0) {
     return Yii::t('int_TIT_MSGT', 'Mensaje Traducido|Mensajes Traducidos', $i);
   }
-  
-	/**
-	 * @return array validation rules for model attributes.
-	 */
-	public function rules()
-	{
-		// NOTE: you should only define rules for those attributes that
-		// will receive user inputs.
-		return array(
-			//array('language', 'length', 'max'=>5),
-			array('translation', 'safe'),
-			// The following rule is used by search().
-			// Please remove those attributes that should not be searched.
-			array('message, category, language, translation', 'safe', 'on'=>'search'),
-		);
-	}
 
-	/**
-	 * @return array relational rules.
-	 */
-	public function relations()
-	{
-		// NOTE: you may need to adjust the relation name and the related
-		// class name for the relations automatically generated below.
-		return array(
-			'language0' => array(self::BELONGS_TO, 'Idioma', 'language'),
-			'msgOrig' => array(self::BELONGS_TO, 'MsgOriginal', 'id'),
-		);
-	}
+  /**
+   * @return array validation rules for model attributes.
+   */
+  public function rules() {
+    // NOTE: you should only define rules for those attributes that
+    // will receive user inputs.
+    return array(
+        //array('language', 'length', 'max'=>5),
+        array('translation', 'safe'),
+        // The following rule is used by search().
+        // Please remove those attributes that should not be searched.
+        array('message, category, language, translation', 'safe', 'on' => 'search'),
+    );
+  }
+
+  /**
+   * @return array relational rules.
+   */
+  public function relations() {
+    // NOTE: you may need to adjust the relation name and the related
+    // class name for the relations automatically generated below.
+    return array(
+        'language0' => array(self::BELONGS_TO, 'Idioma', 'language'),
+        'msgOrig' => array(self::BELONGS_TO, 'MsgOriginal', 'id'),
+    );
+  }
 
-	/**
-	 * @return array customized attribute labels (name=>label)
-	 */
-	public function attributeLabels()
-	{
-		return array(
-			'language' => Yii::t('atr_MSGT_LANGUAGE', 'Idioma'),
-			'category' => Yii::t('atr_MSGT_CATEGORY', 'Categoría'),
-			'translation' => Yii::t('atr_MSGT_TRANSLATION', 'Traducción'),
-      'message' => Yii::t('atr_MSGT_MESSAGE', 'Mensaje'),
-		);
-	}
+  /**
+   * @return array customized attribute labels (name=>label)
+   */
+  public function attributeLabels() {
+    return array(
+        'language' => Yii::t('atr_MSGT_LANGUAGE', 'Idioma'),
+        'category' => Yii::t('atr_MSGT_CATEGORY', 'Categoría'),
+        'translation' => Yii::t('atr_MSGT_TRANSLATION', 'Traducción'),
+        'message' => Yii::t('atr_MSGT_MESSAGE', 'Mensaje'),
+    );
+  }
 
-	/**
-	 * Retrieves a list of models based on the current search/filter conditions.
-	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
-	 */
-	public function search()
-	{
-		// Warning: Please modify the following code to remove attributes that
-		// should not be searched.
+  /**
+   * Retrieves a list of models based on the current search/filter conditions.
+   * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
+   */
+  public function search() {
+    // Warning: Please modify the following code to remove attributes that
+    // should not be searched.
 
-		$criteria=new CDbCriteria;
+    $criteria = new CDbCriteria;
 
-		$criteria->compare('msgOrig.category',$this->category, true);
-		$criteria->compare('msgOrig.message',$this->message, true);
-    $criteria->with='msgOrig';
+    $criteria->compare('msgOrig.category', $this->category, true);
+    $criteria->compare('msgOrig.message', $this->message, true);
+    $criteria->with = 'msgOrig';
     //$criteria->addSearchCondition('msgOrig.message',$this->message);
-		$criteria->compare('language',$this->language,true);
-		$criteria->compare('translation',$this->translation,true);
-		return new CActiveDataProvider($this, array(
-			'criteria'=>$criteria,
-       'sort'=>array('defaultOrder'=>'message',
-           'attributes' =>array('message'=>'msgOrig.message',
-                                '*')),
-		));
-	}
+    if (!Yii::app()->messages->forceTranslation)
+      $criteria->addCondition("t.language <> '" . Yii::app()->sourceLanguage . "'");
+    $criteria->compare('language', $this->language, true);
+    $criteria->compare('translation', $this->translation, true);
+    return new CActiveDataProvider($this, array(
+                'criteria' => $criteria,
+                'sort' => array('defaultOrder' => 'message',
+                    'attributes' => array('message' => 'msgOrig.message',
+                        '*')),
+            ));
+  }
+
 }
 AGREGADO: 2012-12-03
 Para beneficio de los no hispanoparlantes; los métodos, propiedades y funciones pueden utilizarse en inglés también. (escrito en *itálicas*)
 
+AGREGADO: 2013-01-02
+Se cambió la necesidad de "forzar" un idioma inexistente.
+Yii provee ya una función que "fuerza" la traducción (Ver Instalacion).
+La ventaja de este cambio es que permite una función i18n completa.
+sourceLanguage vuelve a su función original,
+language sigue siendo dinámico,
+idiomaAux (langAux) es el idioma que "cumple" un rol universal y no es el "source".
+Ejemplo: 
+idioma XX no está definido o activo, entonces pregunta por "idiomaAux" (langAux) y si este no estuviera "activo", decanta por "sourceLanguage".
+language es dinámico xq pregunto por el idioma del navegador, y cambia a voluntad del usuario si se muestra el selector.
+sourceLanguage podría ser "es" y "idiomaAux" podría ser "en".
+Cuando se "crean" las tablas, la de idioma tendrá 2 registros: uno para el idioma sourceLanguage activado, y el "idiomaAux" desactivado.
+
+####Importante
+Dado que el uso de i18n permite la utilización de cualquier idioma, es NECESARIO que la base de datos tenga su juego de caracteres com utf8 y el cotejamiento como utf8_general_ci.
+Si no estuviera configurado de ese modo, se representarán los caracteres de manera errónea para idiomas con escrituras como la kanji, árabe, hebrea, etc...
+Ejecutar esta instrucción en mysql resolvería el problema:
+ALTER DATABASE mibbdd DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
+
 ----
 ###Instalación
 Copiar la carpeta 'gemi' dentro de "modules". O bien, crear una carpeta 'gemi' dentro de protected/modules y  descargar del [repositorio](https://bitbucket.org/dgeaperez/gemi/) el código dentro de ella.
 Editar las siguientes secciones de config/main.php:
 
 	//Forzar que el idioma original nunca exista
-	'sourceLanguage' => '¡¡',
+	'sourceLanguage' => 'es',
 	'language' => 'es',
  
  	'import'=>array(
 	    'gemi'=>array(
 	        'mostrarTodos'=>true,
 	        'mostrarInactivos'=>true,
+          'idiomaAux' => 'en',
 	    ), 
  
 	'messages' => array(
 	    'sourceMessageTable' => 'tbl_msgOriginal',
 	    'translatedMessageTable' => 'tbl_msgTraducido',
 	    'onMissingTranslation' => array('MensajeATraducir', 'load'),
+      'forceTranslation' => true, //Indicará si se permite editar o no los textos en el "código"
 	),
 
 No es necesario crear tablas en la base de datos, se generan automáticamente.
 ADDED: 2012-12-03
 For non Spanish spoken people benefit; methods, properties and functions can be used in english language too. (*italic* form)
 
+AGREGADO: 2013-01-02
+There is no need to "force" to an inexistant language.
+Yii provides a function to "force" the translation (See Installation)
+The adventage of this change is enable a complete i18n implementation.
+sourceLanguage parameter backs to its original use, and language parameter still is dynamic, idiomaAux (langAux) is a new parameter to set the "auxiliar" language to use before to set sourceLanguage to translate.
+Example: 
+Language XX is not defined or active, then GeMI ask for "idiomaAux" (langAux) and if it isn't active, sourceLanguage will be used.
+language is dynamic, because is the language odf the browser, and it can be changed by the user if the language selector is showed.
+sourceLanguage could be "es" and "idiomaAux" could be "en".
+When the tables are created, the language's table will have 2 records not soft deleted: "sourceLanguage" activado, and "idiomaAux" desactivado.
+
+####Important
+Because the use of i18n lets use of any language, the database MUST have utf8 as character set and utf8_general_ci as collation. 
+If the database isn't set in that way, the strings will have a wrong representation for languages like arabian, kanji, hebrew, etc...
+You can run this SQL statament to solve that:
+ALTER DATABASE mibbdd DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
+
 ----
 ###Installation
 Copy'gemi' folder inside 'modules'. Or well, Create a folder, named 'gemi', inside protected/modules and donwload inside the source code from [repository](https://bitbucket.org/dgeaperez/gemi/).
 Edit config/main.php:
 
 	//Forces source language never exists
-	'sourceLanguage' => '¡¡',
+	'sourceLanguage' => 'es',
 	'language' => 'es',
  
  	'import'=>array(
 	    'gemi'=>array(
 	        'mostrarTodos'=>true,     //showAll
 	        'mostrarInactivos'=>true, //showDeactivated
+          'idiomaAux' => 'en',
 	    ), 
  
 	'messages' => array(
 	    'sourceMessageTable' => 'tbl_msgOriginal',
 	    'translatedMessageTable' => 'tbl_msgTraducido',
 	    'onMissingTranslation' => array('MensajeATraducir', 'load'),
+      'forceTranslation' => true, //Lets or not to modify the text "hard coded"
 	),
 
 The tables are created "automagically".

views/msgTraducido/_search.php

 
 	<div class="row">
 		<?php echo $form->label($model,'language'); ?>
-		<?php echo $form->dropDownList($model,'language',array(""=>Yii::t('int_GRL_TODOS', 'Todos'))+$gemi->listarIdiomasVigentes); ?>
+		<?php echo $form->dropDownList($model,'language',array(""=>Yii::t('int_GRL_TODOS', 'Todos'))+(
+                        Yii::app()->messages->forceTranslation ? 
+                        $gemi->listarIdiomasVigentes :
+                        $gemi->ListarIdiomasPersonalizado("idiBaja IS NULL AND idiCodigo <> '".Yii::app()->sourceLanguage."'"))); ?>
 	</div>
 
 	<div class="row">

views/msgTraducido/index.php

         array(
             'name' => 'language',
             'value' => '$data->language0->idiDescripcion',
-            'filter' => $gemi->listarIdiomasVigentes,
+            'filter' => Yii::app()->messages->forceTranslation ? 
+                        $gemi->listarIdiomasVigentes :
+                        $gemi->ListarIdiomasPersonalizado("idiBaja IS NULL AND idiCodigo <> '".Yii::app()->sourceLanguage."'"),
         ),
         'translation',
         array(
                 'update' => array(
                     'url' => 'Yii::app()->controller->createUrl("update",array("id"=>$data->id, "lng"=>$data->language))',
                     'click' => 'updateDialogUpdate',
-                    //'visible'=>'$data->language0->idiCodigo!="es"',
+                    'visible'=>'($data->language0->idiCodigo!=Yii::app()->sourceLanguage) || Yii::app()->messages->forceTranslation',
                 ),
             ),
             'template' => '{update}',