summaryrefslogtreecommitdiff
path: root/demos/quickstart/protected/QuickStartGlobalization.php
blob: 90d622803106c4f7d53af37c8faf6cfe5e5609ab (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
<?php

Prado::using('System.I18N.core.CultureInfo');
Prado::using('System.Web.THttpCookie');

class QuickStartGlobalization extends TGlobalizationAutoDetect
{
	public function init($xml)
	{
		parent::init($xml);
		$this->Application->OnBeginRequest[] = array($this, 'beginRequest');
	}

	public function beginRequest($sender, $param)
	{
		if(null == ($culture=$this->Request['lang']))
		{
			if(null !== ($cookie=$this->Request->Cookies['lang']))
				$culture = $cookie->getValue();
		}

		if(is_string($culture))
		{
			$info = new CultureInfo();
			if($info->validCulture($culture))
			{
				$this->setCulture($culture);
				$this->Response->Cookies[] = new THttpCookie('lang',$culture);
			}
		}
	}
}