i18n, #16
git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@134 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
This commit is contained in:
@ -17,7 +17,7 @@ class Route
|
|||||||
protected $params;
|
protected $params;
|
||||||
protected $layout;
|
protected $layout;
|
||||||
|
|
||||||
public function __construct($route, $action, $params = null, $layout = null)
|
public function __construct($route, $action, $params = array(), $layout = null)
|
||||||
{
|
{
|
||||||
$this->route = $route;
|
$this->route = $route;
|
||||||
$this->action = $action;
|
$this->action = $action;
|
||||||
|
@ -23,7 +23,7 @@ class Router
|
|||||||
*/
|
*/
|
||||||
protected $route;
|
protected $route;
|
||||||
|
|
||||||
public function add($name, $route, $action, $params = null, $layout = null)
|
public function add($name, $route, $action, $params = array(), $layout = null)
|
||||||
{
|
{
|
||||||
if (!$layout) {
|
if (!$layout) {
|
||||||
$layout = $this->default_layout;
|
$layout = $this->default_layout;
|
||||||
|
110
i18n/I18N.php
Normal file
110
i18n/I18N.php
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @copyright NetMonsters <team@netmonsters.ru>
|
||||||
|
* @link http://netmonsters.ru
|
||||||
|
* @package Majestic
|
||||||
|
* @subpackage Model
|
||||||
|
* @since 2010-02-23
|
||||||
|
* @version SVN: $Id$
|
||||||
|
* @filesource $URL$
|
||||||
|
*/
|
||||||
|
|
||||||
|
class I18N
|
||||||
|
{
|
||||||
|
|
||||||
|
static protected $domain = 'default';
|
||||||
|
static protected $locales = array();
|
||||||
|
static protected $bidi = array();
|
||||||
|
static protected $langs = array();
|
||||||
|
static protected $default = 'ru';
|
||||||
|
|
||||||
|
static protected $lang = '';
|
||||||
|
static protected $locale = '';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $lang default language set
|
||||||
|
*/
|
||||||
|
static public function init()
|
||||||
|
{
|
||||||
|
$config = Config::get(__CLASS__);
|
||||||
|
|
||||||
|
self::$locales = $config['locales'];
|
||||||
|
|
||||||
|
if (isset($config['bidi'])) {
|
||||||
|
self::$bidi = $config['bidi'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($config['default'])) {
|
||||||
|
self::$default = $config['default'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// language switching
|
||||||
|
if ($lang = Env::Post('lang')) {
|
||||||
|
self::setLang($lang);
|
||||||
|
header('Location: ' . Env::getRequestUri());
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$lang = Env::Cookie('lang', self::getAcceptLanguage());
|
||||||
|
self::setLang(self::$lang);
|
||||||
|
self::$locale = self::$locales[self::$lang];
|
||||||
|
|
||||||
|
//var_dump(self::$locale);
|
||||||
|
putenv('LANG=' . self::$locale);
|
||||||
|
setlocale(LC_ALL, self::$locale . '.UTF-8');
|
||||||
|
bindtextdomain(self::$domain, PATH . '/' . APP . '/src/i18n/');
|
||||||
|
textdomain(self::$domain);
|
||||||
|
bind_textdomain_codeset(self::$domain, 'UTF-8');
|
||||||
|
}
|
||||||
|
|
||||||
|
static protected function getAcceptLanguage()
|
||||||
|
{
|
||||||
|
$lang = self::$default;
|
||||||
|
|
||||||
|
if ($accept = Env::Server('HTTP_ACCEPT_LANGUAGE')) {
|
||||||
|
$accept = explode(',', $accept);
|
||||||
|
foreach ($accept as $a) {
|
||||||
|
if (($pos = strpos($a, ';q=')) !== false) {
|
||||||
|
$a = substr($a, 0, $pos);
|
||||||
|
}
|
||||||
|
if (($pos = strpos($a, '-')) !== false) {
|
||||||
|
$a = substr($a, 0, $pos) . '_' . strtoupper(substr($a, $pos + 1));
|
||||||
|
}
|
||||||
|
if (isset(self::$locales[$a])) {
|
||||||
|
$lang = $a;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ($key = array_search($a, self::$locales)) {
|
||||||
|
$lang = $key;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $lang;
|
||||||
|
}
|
||||||
|
|
||||||
|
static protected function setLang($lang)
|
||||||
|
{
|
||||||
|
if (!array_key_exists($lang, self::$locales)) {
|
||||||
|
$lang = self::$default;
|
||||||
|
}
|
||||||
|
Env::setCookie('lang', $lang, time()+60*60*24*30, '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
static public function getLang()
|
||||||
|
{
|
||||||
|
return self::$lang;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static public function setLangs($langs = array())
|
||||||
|
{
|
||||||
|
self::$langs = $langs;
|
||||||
|
}
|
||||||
|
|
||||||
|
static public function getLangs()
|
||||||
|
{
|
||||||
|
return self::$langs;
|
||||||
|
}
|
||||||
|
}
|
29
view/helpers/ViewHelperTitle.php
Normal file
29
view/helpers/ViewHelperTitle.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @copyright NetMonsters <team@netmonsters.ru>
|
||||||
|
* @link http://netmonsters.ru
|
||||||
|
* @package Majestic
|
||||||
|
* @subpackage View
|
||||||
|
* @since 2010-03-16
|
||||||
|
* @version SVN: $Id$
|
||||||
|
* @filesource $URL$
|
||||||
|
*/
|
||||||
|
|
||||||
|
class ViewHelperTitle extends ViewHelper
|
||||||
|
{
|
||||||
|
|
||||||
|
public function title($string = false)
|
||||||
|
{
|
||||||
|
if ($string) {
|
||||||
|
$data = Registry::get(__CLASS__, array());
|
||||||
|
$data[] = $string;
|
||||||
|
Registry::set(__CLASS__, $data);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return implode(' - ', Registry::get(__CLASS__, array()));
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user