diff options
author | tof <> | 2008-03-09 15:02:01 +0000 |
---|---|---|
committer | tof <> | 2008-03-09 15:02:01 +0000 |
commit | 6b2547714960641dd55b341061dab1cba93ae203 (patch) | |
tree | 0ff8ff125cf188ca12526e95a5ac0b49b908f43e /framework/I18N | |
parent | d3e8a0e6a7737bb6b847bac325325f8933d6cd76 (diff) |
Fixed #636
Diffstat (limited to 'framework/I18N')
-rw-r--r-- | framework/I18N/TTranslate.php | 8 | ||||
-rw-r--r-- | framework/I18N/Translation.php | 34 |
2 files changed, 23 insertions, 19 deletions
diff --git a/framework/I18N/TTranslate.php b/framework/I18N/TTranslate.php index 409015ed..327119fd 100644 --- a/framework/I18N/TTranslate.php +++ b/framework/I18N/TTranslate.php @@ -239,17 +239,17 @@ class TTranslate extends TI18NControl if(is_null($config = $app->getTranslationConfiguration()))
return strtr($text, $subs);
- Translation::init();
-
$catalogue = $this->getCatalogue();
if(empty($catalogue) && isset($config['catalogue']))
$catalogue = $config['catalogue'];
-
+ if (empty($catalogue)) $catalogue='messages';
+ Translation::init($catalogue);
+
$key = $this->getKey();
if(!empty($key)) $text = $key;
//translate it
- return Translation::formatter()->format($text,
+ return Translation::formatter($catalogue)->format($text,
$subs, $catalogue, $this->getCharset());
}
}
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;
}
|