summaryrefslogtreecommitdiff
path: root/framework/I18N/TI18NControl.php
blob: d784dfc3460c5207dec72aace4455de85a9fcd28 (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
<?php
/**
 * Base I18N component.
 *
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
 * @link https://github.com/pradosoft/prado
 * @copyright Copyright &copy; 2005-2015 The PRADO Group
 * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
 * @package System.I18N
 */


/**
 * TI18NControl class.
 *
 * Base class for I18N components, providing Culture and Charset properties.
 * Namespace: System.I18N
 *
 * Properties
 * - <b>Culture</b>, string,
 *   <br>Gets or sets the culture for formatting. If the Culture property
 *   is not specified. The culture from the Application/Page is used.
 * - <b>Charset</b>, string,
 *   <br>Gets or sets the charset for both input and output.
 *   If the Charset property is not specified. The charset from the
 *   Application/Page is used. The default is UTF-8.
 *
 * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
 * @version v1.0, last update on Sat Dec 11 15:25:11 EST 2004
 * @package System.I18N
 */
class TI18NControl extends TControl
{
	/**
	 * Gets the charset.
	 * It is evaluated in the following order:
	 * 1) application charset,
	 * 2) the default charset in globalization
	 * 3) UTF-8
	 * @return string charset
	 */
	public function getCharset()
	{
		$app = $this->getApplication()->getGlobalization(false);

		//instance charset
		$charset = $this->getViewState('Charset','');

		//fall back to globalization charset
		if(empty($charset))
			$charset = ($app===null) ? '' : $app->getCharset();

		//fall back to default charset
		if(empty($charset))
			$charset = ($app===null) ? 'UTF-8' : $app->getDefaultCharset();

		return $charset;
	}

	/**
	 * Sets the charset for message output
	 * @param string the charset, e.g. UTF-8
	 */
	public function setCharset($value)
	{
		$this->setViewState('Charset',$value,'');
	}


	/**
	 * Get the specific culture for this control.
	 * @param parameter
	 * @return string culture identifier.
	 */
	public function getCulture()
	{
		return $this->getViewState('Culture','');
	}

	/**
	 * Get the custom culture identifier.
	 * @param string culture identifier.
	 */
	public function setCulture($culture)
	{
		$this->setViewState('Culture',$culture,'');
	}
}