diff options
author | xue <> | 2006-04-07 12:35:59 +0000 |
---|---|---|
committer | xue <> | 2006-04-07 12:35:59 +0000 |
commit | 021501cb16c964b4bb43ecef6688cba64ecb257d (patch) | |
tree | 4b08b0b9ed426eb208c983db8fb4a6ac780303eb /framework/PradoBase.php | |
parent | 4226093cc034dfbd25a5b9e9aee2778e795ee42a (diff) |
Merged from 3.0 branch 867
Diffstat (limited to 'framework/PradoBase.php')
-rw-r--r-- | framework/PradoBase.php | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/framework/PradoBase.php b/framework/PradoBase.php index 59ab5b14..5325005a 100644 --- a/framework/PradoBase.php +++ b/framework/PradoBase.php @@ -519,6 +519,47 @@ class PradoBase require_once(PRADO_DIR.'/Util/TVarDumper.php');
return TVarDumper::dump($var,$depth,$highlight);
}
+
+ /**
+ * Localize a text to the locale/culture specified in the globalization handler.
+ * @param string text to be localized.
+ * @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.
+ * @see TTranslate::formatter()
+ * @see TTranslate::init()
+ */
+ public static function localize($text, $parameters=array(), $catalogue=null, $charset=null)
+ {
+ Prado::using('System.I18N.Translation');
+ $app = Prado::getApplication()->getGlobalization();
+
+ $params = array();
+ foreach($parameters as $key => $value)
+ $params['{'.$key.'}'] = $value;
+
+ //no translation handler provided
+ if(($config = $app->getTranslationConfiguration())===null)
+ return strtr($text, $params);
+
+ Translation::init();
+
+ if(empty($catalogue) && isset($config['catalogue']))
+ $catalogue = $config['catalogue'];
+
+ //globalization charset
+ $appCharset = $app===null ? '' : $app->getCharset();
+
+ //default charset
+ $defaultCharset = ($app===null) ? 'UTF-8' : $app->getDefaultCharset();
+
+ //fall back
+ if(empty($charset)) $charset = $appCharset;
+ if(empty($charset)) $charset = $defaultCharset;
+
+ return Translation::formatter()->format($text,$params,$catalogue,$charset);
+ }
}
/**
|