From 4835704a04cf5aa5ec71a8aef902d54b9c6cae82 Mon Sep 17 00:00:00 2001 From: wei <> Date: Fri, 6 Jan 2006 04:42:44 +0000 Subject: Adding I18N support. --- framework/I18N/TTranslateParameter.php | 113 +++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 framework/I18N/TTranslateParameter.php (limited to 'framework/I18N/TTranslateParameter.php') diff --git a/framework/I18N/TTranslateParameter.php b/framework/I18N/TTranslateParameter.php new file mode 100644 index 00000000..f162d642 --- /dev/null +++ b/framework/I18N/TTranslateParameter.php @@ -0,0 +1,113 @@ + + * @version $Revision: 1.2 $ $Date: 2005/01/05 03:15:13 $ + * @package System.I18N + */ + +/** + * TTranslateParameter component should be used inside the TTranslate component to + * allow parameter substitution. + * + * For example, the strings "{greeting}" and "{name}" will be replace + * with the values of "Hello" and "World", respectively. + * The substitution string must be enclose with "{" and "}". + * The parameters can be further translated by using TTranslate. + * + * + * {greeting} {name}! + * World + * Hello + * + * + * + * Namespace: System.I18N + * + * Properties + * - Key, string, required. + *
Gets or sets the string in TTranslate to substitute. + * - Trim, boolean, + *
Gets or sets an option to trim the contents of the TParam. + * Default is to trim the contents. + * + * @author Xiang Wei Zhuo + * @version v3.0, last update on Friday, 6 January 2006 + * @package System.I18N + */ +class TTranslateParameter extends TControl +{ + /** + * The substitution key. + * @var string + */ + protected $key; + + /** + * To trim or not to trim the contents. + * @var boolean + */ + protected $trim = true; + + /** + * Get the parameter substitution key. + * @return string substitution key. + */ + public function getKey() + { + if(empty($this->key)) + throw new TException('The Key property must be specified.'); + return $this->key; + } + + /** + * Set the parameter substitution key. + * @param string substitution key. + */ + public function setKey($value) + { + $this->key = $value; + } + + /** + * Set the option to trim the contents. + * @param boolean trim or not. + */ + public function setTrim($value) + { + $this->trim = TPropertyValue::ensureBoolean($value); + } + + /** + * Trim the content or not. + * @return boolean trim or not. + */ + public function getTrim() + { + return $this->trim; + } + + /** + * @return string parameter contents. + */ + public function getParameter() + { + $textWriter = new TTextWriter; + $this->renderControl(new THtmlWriter($textWriter)); + return $this->getTrim() ? + trim($textWriter->flush()) : $textWriter->flush(); + } +} + +?> \ No newline at end of file -- cgit v1.2.3