diff options
Diffstat (limited to 'lib/prado/framework/I18N/TGlobalizationAutoDetect.php')
-rw-r--r-- | lib/prado/framework/I18N/TGlobalizationAutoDetect.php | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/prado/framework/I18N/TGlobalizationAutoDetect.php b/lib/prado/framework/I18N/TGlobalizationAutoDetect.php new file mode 100644 index 0000000..2412712 --- /dev/null +++ b/lib/prado/framework/I18N/TGlobalizationAutoDetect.php @@ -0,0 +1,49 @@ +<?php +/** + * TMultiView and TView class file. + * + * @author Wei Zhuo<weizhuo[at]gmail[dot]com> + * @link https://github.com/pradosoft/prado + * @copyright Copyright © 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; + } +} + |