From ed3e43d30524a76969fb7d42cb5e613c2e1a1d9a Mon Sep 17 00:00:00 2001 From: wei <> Date: Fri, 6 Jan 2006 05:16:25 +0000 Subject: Changing property scopes in TGlobalization --- framework/I18N/TDateFormat.php | 4 +- framework/I18N/TGlobalization.php | 47 +++++++++++++++++---- framework/I18N/TGlobalizationAutoDetect.php | 2 +- framework/I18N/TI18NControl.php | 2 +- framework/I18N/TNumberFormat.php | 4 +- framework/I18N/Translation.php | 8 ++-- tests/FunctionalTests/protected/application.xml | 2 +- .../protected/pages/I18N/BasicI18N.page | 2 +- .../FunctionalTests/protected/runtime/config.cache | Bin 1543 -> 1543 bytes 9 files changed, 50 insertions(+), 21 deletions(-) diff --git a/framework/I18N/TDateFormat.php b/framework/I18N/TDateFormat.php index 1226fd6f..985f5115 100644 --- a/framework/I18N/TDateFormat.php +++ b/framework/I18N/TDateFormat.php @@ -174,12 +174,12 @@ class TDateFormat extends TI18NControl //initialized the default class wide formatter if(is_null(self::$formatter)) - self::$formatter = new DateFormat($app->Culture); + self::$formatter = new DateFormat($app->getCulture()); $culture = $this->getCulture(); //return the specific cultural formatted date time - if(strlen($culture) && $app->Culture !== $culture) + if(strlen($culture) && $app->getCulture() !== $culture) { $formatter = new DateFormat($culture); return $formatter->format($this->getValue(), diff --git a/framework/I18N/TGlobalization.php b/framework/I18N/TGlobalization.php index 473fe315..4e6d030c 100644 --- a/framework/I18N/TGlobalization.php +++ b/framework/I18N/TGlobalization.php @@ -54,19 +54,19 @@ class TGlobalization extends TModule * The current charset. * @var string */ - public $Charset='UTF-8'; + protected $_charset='UTF-8'; /** * The current culture. * @var string */ - public $Culture='en'; + protected $_culture='en'; /** * The content type for the http header * @var string */ - public $ContentType='text/html'; + protected $_contentType='text/html'; /** * Initialize the Culture and Charset for this application. @@ -76,17 +76,46 @@ class TGlobalization extends TModule * @param TXmlElement application configuration */ public function init($xml) - { - $this->Culture = str_replace('-','_',$this->Culture); - $this->_defaultContentType = $this->ContentType; - $this->_defaultCharset = $this->Charset; - $this->_defaultCulture = $this->Culture; + { + $this->_defaultContentType = $this->getContentType(); + $this->_defaultCharset = $this->getCharset(); + $this->_defaultCulture = $this->getCulture(); $config = $xml->getElementByTagName('translation')->getAttributes(); $this->setTranslationConfiguration($config); $this->getApplication()->setGlobalization($this); } + public function getCulture() + { + return $this->_culture; + } + + public function setCulture($culture) + { + $this->_culture = str_replace('-','_',$culture); + } + + public function getCharset() + { + return $this->_charset; + } + + public function setCharset($charset) + { + $this->_charset = $charset; + } + + public function setContentType($type) + { + $this->_contentType = $type; + } + + public function getContentType() + { + return $this->_contentType; + } + /** * @return TMap translation source configuration. */ @@ -153,7 +182,7 @@ class TGlobalization extends TModule */ public function getCultureVariants($culture=null) { - if(is_null($culture)) $culture = $this->Culture; + if(is_null($culture)) $culture = $this->getCulture(); $variants = explode('_', $culture); $result = array(); for(; count($variants) > 0; array_pop($variants)) diff --git a/framework/I18N/TGlobalizationAutoDetect.php b/framework/I18N/TGlobalizationAutoDetect.php index 6cf17bcb..3d550a62 100644 --- a/framework/I18N/TGlobalizationAutoDetect.php +++ b/framework/I18N/TGlobalizationAutoDetect.php @@ -21,7 +21,7 @@ class TGlobalizationAutoDetect extends TGlobalization $http = new HTTPNegotiator(); $languages = $http->getLanguages(); if(count($languages) > 0) - $this->Culture = $languages[0]; + $this->setCulture($languages[0]); } } diff --git a/framework/I18N/TI18NControl.php b/framework/I18N/TI18NControl.php index 01df1332..44e15f2f 100644 --- a/framework/I18N/TI18NControl.php +++ b/framework/I18N/TI18NControl.php @@ -81,7 +81,7 @@ class TI18NControl extends TControl //fall back to globalization charset if(empty($charset)) - $charset = is_null($app) ? '' : $app->Charset; + $charset = is_null($app) ? '' : $app->getCharset(); //fall back to default charset if(empty($charset)) diff --git a/framework/I18N/TNumberFormat.php b/framework/I18N/TNumberFormat.php index 712f548b..9f2de233 100644 --- a/framework/I18N/TNumberFormat.php +++ b/framework/I18N/TNumberFormat.php @@ -179,14 +179,14 @@ class TNumberFormat extends TI18NControl $app = $this->Application->getGlobalization(); //initialized the default class wide formatter if(is_null(self::$formatter)) - self::$formatter = new NumberFormat($app->Culture); + self::$formatter = new NumberFormat($app->getCulture()); $pattern = strlen($this->getPattern()) > 0 ? $this->getPattern() : $this->getType(); $culture = $this->getCulture(); //return the specific cultural formatted number - if(!empty($culture) && $app->Culture != $culture) + if(!empty($culture) && $app->getCulture() != $culture) { $formatter = new NumberFormat($culture); return $formatter->format($this->getValue(),$pattern, diff --git a/framework/I18N/Translation.php b/framework/I18N/Translation.php index 8b420bbf..8f45ff64 100644 --- a/framework/I18N/Translation.php +++ b/framework/I18N/Translation.php @@ -56,12 +56,12 @@ class Translation extends TComponent $config['source'], $config['filename']); - $source->setCulture($app->Culture); + $source->setCulture($app->getCulture()); if($config['cache']) $source->setCache(new MessageCache($config['cache'])); - self::$formatter = new MessageFormat($source, $app->Charset); + self::$formatter = new MessageFormat($source, $app->getCharset()); //save the message on end request Prado::getApplication()->attachEventHandler( @@ -92,7 +92,7 @@ class Translation extends TComponent $config = $app->getTranslationConfiguration(); if(isset($config['autosave'])) { - $formatter->getSource()->setCulture($app->Culture); + $formatter->getSource()->setCulture($app->getCulture()); $formatter->getSource()->save($config['catalogue']); } $onceonly = false; @@ -129,7 +129,7 @@ function localize($text, $parameters=array(), $catalogue=null, $charset=null) $catalogue = $config['catalogue']; //globalization charset - $appCharset = is_null($app) ? '' : $app->Charset; + $appCharset = is_null($app) ? '' : $app->getCharset(); //default charset $defaultCharset = (is_null($app)) ? 'UTF-8' : $app->getDefaultCharset(); diff --git a/tests/FunctionalTests/protected/application.xml b/tests/FunctionalTests/protected/application.xml index 0bc6a7c7..c4ea0be2 100644 --- a/tests/FunctionalTests/protected/application.xml +++ b/tests/FunctionalTests/protected/application.xml @@ -7,7 +7,7 @@ - + diff --git a/tests/FunctionalTests/protected/runtime/config.cache b/tests/FunctionalTests/protected/runtime/config.cache index 1f1f82fd..33317f88 100644 Binary files a/tests/FunctionalTests/protected/runtime/config.cache and b/tests/FunctionalTests/protected/runtime/config.cache differ -- cgit v1.2.3