From 6b2547714960641dd55b341061dab1cba93ae203 Mon Sep 17 00:00:00 2001 From: tof <> Date: Sun, 9 Mar 2008 15:02:01 +0000 Subject: Fixed #636 --- framework/I18N/Translation.php | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'framework/I18N/Translation.php') diff --git a/framework/I18N/Translation.php b/framework/I18N/Translation.php index 7394842b..60e55ba0 100644 --- a/framework/I18N/Translation.php +++ b/framework/I18N/Translation.php @@ -28,18 +28,19 @@ Prado::using('System.I18N.core.MessageFormat'); class Translation extends TComponent { /** - * The string formatter. This is a class static variable. - * @var MessageFormat + * The array of formatters. We define 1 formatter per translation catalog + * This is a class static variable. + * @var array */ - protected static $formatter; + protected static $formatters=array(); /** * Initialize the TTranslate translation components */ - public static function init() + public static function init($catalogue='messages') { //initialized the default class wide formatter - if(is_null(self::$formatter)) + if(is_null(self::$formatters[$catalogue])) { $app = Prado::getApplication()->getGlobalization(); $config = $app->getTranslationConfiguration(); @@ -52,11 +53,11 @@ class Translation extends TComponent if($config['cache']) $source->setCache(new MessageCache($config['cache'])); - self::$formatter = new MessageFormat($source, $app->getCharset()); + self::$formatters[$catalogue] = new MessageFormat($source, $app->getCharset()); //mark untranslated text if($ps=$config['marker']) - self::$formatter->setUntranslatedPS(array($ps,$ps)); + self::$formatters[$catalogue]->setUntranslatedPS(array($ps,$ps)); //save the message on end request Prado::getApplication()->attachEventHandler( @@ -69,9 +70,9 @@ class Translation extends TComponent * @return MessageFormat formattter. * @see localize() */ - public static function formatter() + public static function formatter($catalogue='messages') { - return self::$formatter; + return self::$formatters[$catalogue]; } /** @@ -81,14 +82,17 @@ class Translation extends TComponent { static $onceonly = true; - if($onceonly && !is_null($formatter = self::$formatter)) + if($onceonly) { - $app = Prado::getApplication()->getGlobalization(); - $config = $app->getTranslationConfiguration(); - if(isset($config['autosave'])) + foreach (self::$formatters as $catalogue=>$formatter) { - $formatter->getSource()->setCulture($app->getCulture()); - $formatter->getSource()->save($config['catalogue']); + $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