Author: rande Date: 2010-03-10 22:42:20 +0100 (Wed, 10 Mar 2010) New Revision: 28465
Modified: plugins/mgI18nPlugin/branches/sf1.2/lib/mgI18N.class.php plugins/mgI18nPlugin/branches/sf1.2/lib/sfMessageSource_mgMySQL.class.php plugins/mgI18nPlugin/branches/sf1.3/lib/mgI18N.class.php plugins/mgI18nPlugin/branches/sf1.3/lib/sfMessageSource_mgMySQL.class.php Log: [mgI18nPlugin] fix bugs ... Modified: plugins/mgI18nPlugin/branches/sf1.2/lib/mgI18N.class.php =================================================================== --- plugins/mgI18nPlugin/branches/sf1.2/lib/mgI18N.class.php 2010-03-10 16:45:04 UTC (rev 28464) +++ plugins/mgI18nPlugin/branches/sf1.2/lib/mgI18N.class.php 2010-03-10 21:42:20 UTC (rev 28465) @@ -11,7 +11,7 @@ /** * - * + * * @package mgI18nPlugin * @author Thomas Rabaix <[email protected]> * @version SVN: $Id$ @@ -24,24 +24,24 @@ parent::initialize($configuration, $cache, $options); $this->options['learning_mode'] = isset($this->options['learning_mode']) ? $this->options['learning_mode'] : false; - + $this->configuration->loadHelpers(array('Text')); } - + public function __destruct() { if($this->options['learning_mode']) { - // save only one debug mode + // save only on learning mode if(!$this->getMessageSource() instanceof sfMessageSource_mgMySQL) { throw new sfException('The message source must be an instance of sfMessageSource_mgMySQL'); } - + $this->getMessageSource()->save(); } } - + /** * Gets the translation for the given string * @@ -53,19 +53,21 @@ */ public function __($string, $args = array(), $catalogue = 'messages') { - + + $catalogue = $catalogue === null ? 'messages' : $catalogue; + // get the translated message - // if the debug is on then the message will be prefixed and suffixed + // if the debug is on then the message will be prefixed and suffixed $message = $this->getMessageFormat()->format($string, $args, $catalogue); - + $catalogue = sprintf('%s.%s', $this->getMessageSource()->getApplicationName(), $catalogue ); if(!sfConfig::get('mg_i18n_enabled')) { - + return $message; } - + $pseudo_string = $string; if($this->options['debug']) { @@ -97,7 +99,7 @@ // append the message, so it can be stored into the database $this->getMessageSource()->appendRequestedMessage($value, $catalogue); - return $pseudo_string; + return $pseudo_string != $message ? $message : $pseudo_string; } /** @@ -106,25 +108,20 @@ */ public function getRequestedMessages() { - + return $this->getMessageSource()->getRequestedMessages(); } - public function listenToChangeCultureEvent(sfEvent $event) - { - parent::listenToChangeCultureEvent($event); - $this->to_analyse = array(); - } - - public function listenToChangeActionEvent(sfEvent $event) - { - // change message source directory to our module - parent::listenToChangeActionEvent($event); - } - + /** + * return the language used in a given catalogue name + * + * @static + * @param string $catalogue the catalogue name + * @return string language + */ public static function getLanguage($catalogue) { - + return substr($catalogue, strrpos($catalogue, '.') + 1); } } \ No newline at end of file Modified: plugins/mgI18nPlugin/branches/sf1.2/lib/sfMessageSource_mgMySQL.class.php =================================================================== --- plugins/mgI18nPlugin/branches/sf1.2/lib/sfMessageSource_mgMySQL.class.php 2010-03-10 16:45:04 UTC (rev 28464) +++ plugins/mgI18nPlugin/branches/sf1.2/lib/sfMessageSource_mgMySQL.class.php 2010-03-10 21:42:20 UTC (rev 28465) @@ -57,7 +57,6 @@ } // try to get the PDO connection object from the configuration - if($connection == null) { $configuration = sfProjectConfiguration::getActive(); @@ -134,7 +133,6 @@ } $this->untranslated[$catalogue][md5($message_information['source'])] = $message_information; - } /** @@ -350,7 +348,7 @@ */ function save($catalogue = 'messages') { - $select_message_stm = $this->pdo->prepare("SELECT * FROM trans_unit WHERE target = ? AND cat_id = ? LIMIT 1"); + $select_message_stm = $this->pdo->prepare("SELECT * FROM trans_unit WHERE source = ? AND cat_id = ? LIMIT 1"); $insert_message_stm = $this->pdo->prepare("INSERT INTO trans_unit (cat_id, source, target) VALUES (?, ?, ?)"); foreach($this->getRequestedMessages() as $catalogue => $messages) @@ -367,15 +365,15 @@ foreach($messages as $message) { - $result = $select_message_stm->execute(array($message['source'], $cat_id)); + $select_message_stm->execute(array($message['source'], $cat_id)); $trans_unit = $select_message_stm->fetchAll(PDO::FETCH_ASSOC); - + if(count($trans_unit) == 1) { - + continue; } - + $insert_message_stm->execute(array($cat_id, $message['source'], $message['source'])); } } @@ -441,6 +439,6 @@ public function getId() { - return md5(sfConfig::get('app_mgI18nPlugin_connection')); + return md5($this->source); } } Modified: plugins/mgI18nPlugin/branches/sf1.3/lib/mgI18N.class.php =================================================================== --- plugins/mgI18nPlugin/branches/sf1.3/lib/mgI18N.class.php 2010-03-10 16:45:04 UTC (rev 28464) +++ plugins/mgI18nPlugin/branches/sf1.3/lib/mgI18N.class.php 2010-03-10 21:42:20 UTC (rev 28465) @@ -11,7 +11,7 @@ /** * - * + * * @package mgI18nPlugin * @author Thomas Rabaix <[email protected]> * @version SVN: $Id$ @@ -24,24 +24,24 @@ parent::initialize($configuration, $cache, $options); $this->options['learning_mode'] = isset($this->options['learning_mode']) ? $this->options['learning_mode'] : false; - + $this->configuration->loadHelpers(array('Text')); } - + public function __destruct() { if($this->options['learning_mode']) { - // save only one debug mode + // save only on debug mode if(!$this->getMessageSource() instanceof sfMessageSource_mgMySQL) { throw new sfException('The message source must be an instance of sfMessageSource_mgMySQL'); } - + $this->getMessageSource()->save(); } } - + /** * Gets the translation for the given string * @@ -53,16 +53,18 @@ */ public function __($string, $args = array(), $catalogue = 'messages') { - + + $catalogue = $catalogue === null ? 'messages' : $catalogue; + // get the translated message - // if the debug is on then the message will be prefixed and suffixed + // if the debug is on then the message will be prefixed and suffixed $message = $this->getMessageFormat()->format($string, $args, $catalogue); - + $catalogue = sprintf('%s.%s', $this->getMessageSource()->getApplicationName(), $catalogue ); if(!sfConfig::get('mg_i18n_enabled')) { - + return $message; } @@ -97,7 +99,7 @@ // append the message, so it can be stored into the database $this->getMessageSource()->appendRequestedMessage($value, $catalogue); - return $pseudo_string; + return $pseudo_string != $message ? $message : $pseudo_string; } /** @@ -106,25 +108,13 @@ */ public function getRequestedMessages() { - + return $this->getMessageSource()->getRequestedMessages(); } - public function listenToChangeCultureEvent(sfEvent $event) - { - parent::listenToChangeCultureEvent($event); - $this->to_analyse = array(); - } - - public function listenToChangeActionEvent(sfEvent $event) - { - // change message source directory to our module - parent::listenToChangeActionEvent($event); - } - public static function getLanguage($catalogue) { - + return substr($catalogue, strrpos($catalogue, '.') + 1); } } \ No newline at end of file Modified: plugins/mgI18nPlugin/branches/sf1.3/lib/sfMessageSource_mgMySQL.class.php =================================================================== --- plugins/mgI18nPlugin/branches/sf1.3/lib/sfMessageSource_mgMySQL.class.php 2010-03-10 16:45:04 UTC (rev 28464) +++ plugins/mgI18nPlugin/branches/sf1.3/lib/sfMessageSource_mgMySQL.class.php 2010-03-10 21:42:20 UTC (rev 28465) @@ -57,7 +57,6 @@ } // try to get the PDO connection object from the configuration - if($connection == null) { $configuration = sfProjectConfiguration::getActive(); @@ -134,7 +133,6 @@ } $this->untranslated[$catalogue][md5($message_information['source'])] = $message_information; - } /** @@ -350,7 +348,7 @@ */ function save($catalogue = 'messages') { - $select_message_stm = $this->pdo->prepare("SELECT * FROM trans_unit WHERE target = ? AND cat_id = ? LIMIT 1"); + $select_message_stm = $this->pdo->prepare("SELECT * FROM trans_unit WHERE source = ? AND cat_id = ? LIMIT 1"); $insert_message_stm = $this->pdo->prepare("INSERT INTO trans_unit (cat_id, source, target) VALUES (?, ?, ?)"); foreach($this->getRequestedMessages() as $catalogue => $messages) @@ -367,7 +365,7 @@ foreach($messages as $message) { - $result = $select_message_stm->execute(array($message['source'], $cat_id)); + $select_message_stm->execute(array($message['source'], $cat_id)); $trans_unit = $select_message_stm->fetchAll(PDO::FETCH_ASSOC); if(count($trans_unit) == 1) @@ -441,6 +439,6 @@ public function getId() { - return md5(sfConfig::get('app_mgI18nPlugin_connection')); + return md5($this->source); } } -- You received this message because you are subscribed to the Google Groups "symfony SVN" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/symfony-svn?hl=en.
