summaryrefslogtreecommitdiff
path: root/lib/prado/framework/I18N/TGlobalizationAutoDetect.php
blob: 241271223e554691a71f904b08ea3b1e4ed6ba9b (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
<?php
/**
 * TMultiView and TView class file.
 *
 * @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
 * @version $Revision: 1.66 $  $Date: ${DATE} ${TIME} $
 * @package System.I18N
 */

/**
 * Import the HTTPNeogtiator
 */
Prado::using('System.I18N.core.HTTPNegotiator');

/**
 * TGlobalizationAutoDetect class will automatically try to resolve the default
 * culture using the user browser language settings.
 *
 * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
 * @version $Revision: 1.66 $  $Date: ${DATE} ${TIME} $
 * @package System.I18N
 */
class TGlobalizationAutoDetect extends TGlobalization
{
	private $_detectedLanguage;

	public function init($xml)
	{
		parent::init($xml);

		//set the culture according to browser language settings
		$http = new HTTPNegotiator();
		$languages = $http->getLanguages();
		if(count($languages) > 0)
		{
			$this->_detectedLanguage=$languages[0];
			$this->setCulture($languages[0]);
		}
	}

	public function getDetectedLanguage()
	{
		return $this->_detectedLanguage;
	}
}