From 3a1a3b8fce61013b277a04e486bd6d75550b04f7 Mon Sep 17 00:00:00 2001 From: rojaro <> Date: Thu, 2 Sep 2010 09:08:14 +0000 Subject: fixed #288 --- framework/I18N/Translation.php | 201 ++++++++++++++++++++--------------------- 1 file changed, 100 insertions(+), 101 deletions(-) diff --git a/framework/I18N/Translation.php b/framework/I18N/Translation.php index a0fa504d..8df36bc6 100644 --- a/framework/I18N/Translation.php +++ b/framework/I18N/Translation.php @@ -1,108 +1,107 @@ - - * @link http://www.pradosoft.com/ + + * @link http://www.pradosoft.com/ * @copyright Copyright © 2005-2008 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - * @package System.I18N - */ - - /** - * Get the MessageFormat class. - */ -Prado::using('System.I18N.core.MessageFormat'); - - -/** - * Translation class. - * - * Provides translation using a static MessageFormatter. - * - * @author Xiang Wei Zhuo - * @version v1.0, last update on Tue Dec 28 11:54:48 EST 2004 - * @package System.I18N - */ -class Translation extends TComponent -{ - /** - * The array of formatters. We define 1 formatter per translation catalog - * This is a class static variable. - * @var array - */ - protected static $formatters=array(); - - /** - * Initialize the TTranslate translation components - */ - public static function init($catalogue='messages') - { + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package System.I18N + */ + +/** + * Get the MessageFormat class. + */ +Prado::using('System.I18N.core.MessageFormat'); + + +/** + * Translation class. + * + * Provides translation using a static MessageFormatter. + * + * @author Xiang Wei Zhuo + * @version v1.0, last update on Tue Dec 28 11:54:48 EST 2004 + * @package System.I18N + */ +class Translation extends TComponent +{ + /** + * The array of formatters. We define 1 formatter per translation catalog + * This is a class static variable. + * @var array + */ + protected static $formatters=array(); + + /** + * Initialize the TTranslate translation components + */ + public static function init($catalogue='messages') + { static $saveEventHandlerAttached=false; - //initialized the default class wide formatter - if(!isset(self::$formatters[$catalogue])) - { - $app = Prado::getApplication()->getGlobalization(); - $config = $app->getTranslationConfiguration(); - $source = MessageSource::factory($config['type'], - $config['source'], - $config['filename']); - - $source->setCulture($app->getCulture()); - - if($config['cache']) - $source->setCache(new MessageCache($config['cache'])); - - self::$formatters[$catalogue] = new MessageFormat($source, $app->getCharset()); - - //mark untranslated text - if($ps=$config['marker']) - self::$formatters[$catalogue]->setUntranslatedPS(array($ps,$ps)); - + //initialized the default class wide formatter + if(!isset(self::$formatters[$catalogue])) + { + $app = Prado::getApplication()->getGlobalization(); + $config = $app->getTranslationConfiguration(); + $source = MessageSource::factory($config['type'], + $config['source'], + $config['filename']); + + $source->setCulture($app->getCulture()); + + if(TPropertyValue::ensureBoolean($config['cache'])) + $source->setCache(new MessageCache($config['cache'])); + + self::$formatters[$catalogue] = new MessageFormat($source, $app->getCharset()); + + //mark untranslated text + if($ps=$config['marker']) + self::$formatters[$catalogue]->setUntranslatedPS(array($ps,$ps)); + //save the message on end request - // Do it only once ! - if (!$saveEventHandlerAttached) + // Do it only once ! + if(!$saveEventHandlerAttached && TPropertyValue::ensureBoolean($config['autosave'])) { - Prado::getApplication()->attachEventHandler( + Prado::getApplication()->attachEventHandler( 'OnEndRequest', array('Translation', 'saveMessages')); $saveEventHandlerAttached=true; - } - } - } - - /** - * Get the static formatter from this component. - * @return MessageFormat formattter. - * @see localize() - */ - public static function formatter($catalogue='messages') - { - return self::$formatters[$catalogue]; - } - - /** - * Save untranslated messages to the catalogue. - */ - public static function saveMessages() - { - static $onceonly = true; - - if($onceonly) - { - foreach (self::$formatters as $catalogue=>$formatter) - { - $app = Prado::getApplication()->getGlobalization(); - $config = $app->getTranslationConfiguration(); - if(isset($config['autosave'])) - { - $formatter->getSource()->setCulture($app->getCulture()); - $formatter->getSource()->save($catalogue); - } - } - $onceonly = false; - } - } -} - + } + } + } + + /** + * Get the static formatter from this component. + * @return MessageFormat formattter. + * @see localize() + */ + public static function formatter($catalogue='messages') + { + return self::$formatters[$catalogue]; + } + + /** + * Save untranslated messages to the catalogue. + */ + public static function saveMessages() + { + static $onceonly = true; + + if($onceonly) + { + foreach (self::$formatters as $catalogue=>$formatter) + { + $app = Prado::getApplication()->getGlobalization(); + $config = $app->getTranslationConfiguration(); + if(isset($config['autosave'])) + { + $formatter->getSource()->setCulture($app->getCulture()); + $formatter->getSource()->save($catalogue); + } + } + $onceonly = false; + } + } +} -- cgit v1.2.3