summaryrefslogtreecommitdiff
path: root/framework/I18N/TTranslateParameter.php
blob: ad87b8e674175a7f3e56d127d04699c7d8a641e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php

/**
 * TParam component.
 * 
 * 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. 
 *
 * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
 * The latest version of PRADO can be obtained from:
 * {@link http://prado.sourceforge.net/}
 *
 * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
 * @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.
 * <code>
 * <com:TTranslate>
 *   {greeting} {name}!
 *   <com:TTranslateParameter Key="name">World</com:TTranslateParameter>
 *   <com:TTranslateParameter Key="greeting">Hello</com:TTranslateParameter>
 * </com:TTranslate>
 * </code>
 *
 * Namespace: System.I18N
 *
 * Properties
 * - <b>Key</b>, string, <b>required</b>.
 *   <br>Gets or sets the string in TTranslate to substitute.
 * - <b>Trim</b>, boolean,
 *   <br>Gets or sets an option to trim the contents of the TParam.
 *   Default is to trim the contents.
 * 
 * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
 * @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;
	}	

	public function getValue()
	{
		return $this->getViewState('Value', '');
	}

	public function setValue($value)
	{
		$this->setViewState('Value', $value, '');
	}

	/**
	 * @return string parameter contents.
	 */
	public function getParameter()
	{
		$value = $this->getValue();
		if(strlen($value) > 0)
			return $value;
		$textWriter = new TTextWriter;
		$this->renderControl(new THtmlWriter($textWriter));
		return $this->getTrim() ? 
			trim($textWriter->flush()) : $textWriter->flush();
	}
}

?>