summaryrefslogtreecommitdiff
path: root/framework/I18N/Translation.php
diff options
context:
space:
mode:
authorxue <>2006-01-21 17:29:40 +0000
committerxue <>2006-01-21 17:29:40 +0000
commit3fcf847e0cadfb9ede930f538c2f277483442175 (patch)
tree12534cf4b29c1d4676fd59ab47adb60e292bcb6c /framework/I18N/Translation.php
parent99b56c855a597c606d349c7063d843539e65a6ed (diff)
BE AWARE: Significant change!
Changed event definition from XXX to OnXXX.
Diffstat (limited to 'framework/I18N/Translation.php')
-rw-r--r--framework/I18N/Translation.php60
1 files changed, 30 insertions, 30 deletions
diff --git a/framework/I18N/Translation.php b/framework/I18N/Translation.php
index 8f45ff64..91cfd6ee 100644
--- a/framework/I18N/Translation.php
+++ b/framework/I18N/Translation.php
@@ -2,11 +2,11 @@
/**
* Translation, static.
- *
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the BSD License.
*
- * Copyright(c) 2004 by Xiang Wei Zhuo.
+ * Copyright(c) 2004 by Xiang Wei Zhuo.
*
* To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
* The latest version of PRADO can be obtained from:
@@ -21,11 +21,11 @@
* Get the MessageFormat class.
*/
Prado::using('System.I18N.core.MessageFormat');
-
+
/**
* Translation class.
- *
+ *
* Provides translation using a static MessageFormatter.
*
* @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
@@ -34,19 +34,19 @@ Prado::using('System.I18N.core.MessageFormat');
*/
class Translation extends TComponent
{
-
+
/**
* The string formatter. This is a class static variable.
- * @var MessageFormat
- */
+ * @var MessageFormat
+ */
protected static $formatter;
-
+
/**
* Initialize the TTranslate translation components
*/
public static function init()
- {
+ {
//initialized the default class wide formatter
if(is_null(self::$formatter))
{
@@ -55,49 +55,49 @@ class Translation extends TComponent
$source = MessageSource::factory($config['type'],
$config['source'],
$config['filename']);
-
+
$source->setCulture($app->getCulture());
-
+
if($config['cache'])
$source->setCache(new MessageCache($config['cache']));
-
+
self::$formatter = new MessageFormat($source, $app->getCharset());
//save the message on end request
Prado::getApplication()->attachEventHandler(
- 'EndRequest', array('Translation', 'saveMessages'));
- }
+ 'OnEndRequest', array('Translation', 'saveMessages'));
+ }
}
-
+
/**
* Get the static formatter from this component.
- * @return MessageFormat formattter.
+ * @return MessageFormat formattter.
* @see localize()
*/
public static function formatter()
{
return self::$formatter;
}
-
+
/**
* Save untranslated messages to the catalogue.
*/
public static function saveMessages()
{
static $onceonly = true;
-
+
if($onceonly && !is_null($formatter = self::$formatter))
{
$app = Prado::getApplication()->getGlobalization();
$config = $app->getTranslationConfiguration();
if(isset($config['autosave']))
- {
+ {
$formatter->getSource()->setCulture($app->getCulture());
$formatter->getSource()->save($config['catalogue']);
}
$onceonly = false;
- }
- }
+ }
+ }
}
/**
@@ -106,15 +106,15 @@ class Translation extends TComponent
* @param array a set of parameters to substitute.
* @param string a different catalogue to find the localize text.
* @param string the input AND output charset.
- * @return string localized text.
+ * @return string localized text.
* @see TTranslate::formatter()
* @see TTranslate::init()
*/
function localize($text, $parameters=array(), $catalogue=null, $charset=null)
{
-
+
$app = Prado::getApplication()->getGlobalization();
-
+
$params = array();
foreach($parameters as $key => $value)
$params['{'.$key.'}'] = $value;
@@ -127,17 +127,17 @@ function localize($text, $parameters=array(), $catalogue=null, $charset=null)
if(empty($catalogue) && isset($config['catalogue']))
$catalogue = $config['catalogue'];
-
+
//globalization charset
- $appCharset = is_null($app) ? '' : $app->getCharset();
-
+ $appCharset = is_null($app) ? '' : $app->getCharset();
+
//default charset
$defaultCharset = (is_null($app)) ? 'UTF-8' : $app->getDefaultCharset();
-
+
//fall back
- if(empty($charset)) $charset = $appCharset;
+ if(empty($charset)) $charset = $appCharset;
if(empty($charset)) $charset = $defaultCharset;
-
+
return Translation::formatter()->format($text,$params,$catalogue,$charset);
}