public static function setLocale($locale) { self::$locale = $locale; if ($locale != DEFAULT_LOCALE) { self::loadArray(); } }
public function beforeAction() { // clear cache when post data arrives if ($this->controller instanceof AdminController) { if ($this->controller->request->isPost()) { $this->clear(); } return true; } if ($this->controller->UserLogin->loggedin() || Registry::get('DEBUG') > DEBUG_PRODUCTION) { return true; } if (!isset($this->config[$this->controller->name][$this->controller->action])) { return true; } if ($this->controller->request->isGet()) { $ttl = $this->config[$this->controller->name][$this->controller->action]; $id = $this->controller->name . '_' . $this->controller->layout . '_' . $this->controller->action . '_' . md5($this->controller->action . http_build_query($this->controller->params) . I18n::locale()); $this->filename = CACHE_DIR . 'views/' . $id . '.html'; if (file_exists($this->filename)) { // read from cache if (filemtime($this->filename) + $ttl > time()) { $rendered = file_get_contents($this->filename); // replace MD5 $rendered = preg_replace('@md5" value="[\\w\\d]+"@', 'md5" value="' . md5($this->controller->request->host . SALT) . '"', $rendered); $rendered = str_replace('</body>', '<!-- cached ' . ephFrame::compileTime() . ' --></body>', $rendered); echo $rendered; die; } } } return true; }
/** * * Initializes the php-gettext * Remember to load first php-gettext * @param string $locale * @param string $charset * @param string $domain */ public static function initialize($locale = 'en_UK', $charset = 'utf-8', $domain = 'messages') { /** * setting the statics so later we can access them from anywhere */ //we allow to choose lang from the url if (Core::config('i18n.allow_query_language') == 1) { if (Core::get('language') !== NULL) { $locale = Core::get('language'); } elseif (Cookie::get('user_language') !== NULL) { $locale = Cookie::get('user_language'); } Cookie::set('user_language', $locale, Core::config('auth.lifetime')); } self::$lang = $locale; //used in i18n kohana self::$locale = $locale; self::$charset = $charset; self::$domain = $domain; //time zone set in the config date_default_timezone_set(Kohana::$config->load('i18n')->timezone); //Kohana core charset, used in the HTML templates as well Kohana::$charset = self::$charset; /** * In Windows LC_MESSAGES are not recognized by any reason. * So we check if LC_MESSAGES is defined to avoid bugs, * and force using gettext */ if (defined('LC_MESSAGES')) { $locale_res = setlocale(LC_MESSAGES, self::$locale); } else { $locale_res = FALSE; } // used with a function money_format setlocale(LC_MONETARY, self::$locale); /** * check if gettext exists if not uses gettext dropin */ if (!function_exists('_') or $locale_res === FALSE or empty($locale_res)) { /** * gettext override * v 1.0.11 * https://launchpad.net/php-gettext/ * We load php-gettext here since Kohana_I18n tries to create the function __() function when we extend it. * PHP-gettext already does this. */ require Kohana::find_file('vendor', 'php-gettext/gettext', 'inc'); T_setlocale(LC_MESSAGES, self::$locale); T_bindtextdomain(self::$domain, DOCROOT . 'languages'); T_bind_textdomain_codeset(self::$domain, self::$charset); T_textdomain(self::$domain); //force to use the gettext dropin self::$dropin = TRUE; } else { bindtextdomain(self::$domain, DOCROOT . 'languages'); bind_textdomain_codeset(self::$domain, self::$charset); textdomain(self::$domain); } }
public function getText($varname, $default = null) { $languageId = I18n::locale(); $languageModelName = 'Text' . ucFirst(substr($languageId, 0, 2)); if (!isset($this->{$languageModelName})) { $languageModelName = 'Text' . ucfirst(substr(Registry::get('I18n.language'), 0, 2)); } if ($this->{$languageModelName} instanceof Model && $this->{$languageModelName}->hasField($varname)) { return coalesce($this->{$languageModelName}->get($varname), $default, false); } }
public function initialize() { parent::initialize(); $this->loadComponent('Flash'); /*$this->loadComponent( 'Auth', [ 'logoutRedirect' => [ 'controller' => 'Pages', 'action' => 'display', 'home' ], 'authorize' => 'Controller', 'unauthorizedRedirect' => '/' // authenticated, but unauthorized ] );*/ // Now set role flags /*$user_id=$this->Auth->user('id'); if(!is_null($user_id)) { $users = TableRegistry::get('Users'); $user=$users->get($user_id, ['contain' => ['Roles']]); $this->isAdmin = false; $this->isTeacher = false; foreach($user->roles as $role) { if($role->title=='admin') $this->isAdmin=true; if($role->title=='teacher') $this->isTeacher=true; } }*/ // The language is initially set in bootstrap.php. If we want to change the language on-the-fly, // such as in clicking the little flags, then we need to store the desired language in the session, // retrieve that value here, and use that value to override the default language. Even though the // default in bootstrap.php is en_EN, we still need to set it here. $lang = $this->request->session()->read('Config.language'); switch ($lang) { case "zh_CN": I18n::locale('zh_CN'); break; case "zh_PN": I18n::locale('zh_PN'); break; case "en_US": I18n::locale('en_US'); break; } }
public function beforeAction() { // set languages for view // @todo move this to language controller or component if (isset($this->Language) && ($this->Languages = $this->Language->findAll())) { // make languages available in the view $this->data->set('Languages', $this->Languages); // set new locale from language_id=[de|en|fr] action foreach ($this->Languages as $Language) { if (!empty($this->params['language_id']) && $Language->id == $this->params['language_id']) { I18n::locale($Language->locale); break; } } // reset locale to default if locale not found in languages foreach ($this->Languages as $Language) { if ($Language->locale == I18n::locale()) { $found = true; } } if (@$found !== true) { I18n::locale(Registry::get('I18n.language')); } } // detect desired content type and return headers and change // action to use different template $layoutContentTypeMapping = array('json' => 'application/json', 'rss' => 'application/rss+xml', 'vcal' => 'text/calendar', 'txt' => 'text/plain'); // response as json if requested if ($this->request->isAjax() && preg_match('@application\\/json|text\\/javascript@i', $this->request->header->get('accept'))) { $this->layout = 'json'; } if (array_key_exists($this->layout, $layoutContentTypeMapping)) { $this->response->header->set('Content-Type', $layoutContentTypeMapping[$this->layout]); $this->action .= '.' . $this->layout; } return parent::beforeAction(); }
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="<?php echo I18n::locale(); ?> "> <head> <title><?php echo strtr(@$pageTitle, array('<q>' => '"', '</q>' => '"')); ?> </title> <!--[if IE 8]><meta http-equiv="X-UA-Compatible" content="IE=7" /><![endif]--> <base href="<?php echo Router::url('admin'); ?> " /> <?php if (isset($MetaTags)) { echo String::indent($MetaTags->render(), 2, TAB, 1); } if (isset($CSS)) { $CSS->addFiles(array('reset', 'simplePreview', 'mainMenu', 'debug', 'admin', 'form', 'login', 'dialog', 'table', 'debug', 'mediaFile')); echo String::indent($CSS->render(), 2, TAB, 1); } // admin favicon if (file_exists('./faviconAdmin.ico')) { echo '<link rel="shortcut icon" type="image/ico" href="' . WEBROOT . 'faviconAdmin.ico" />' . LF; // normal favicon } elseif (file_exists('./favicon.ico')) { echo '<link rel="shortcut icon" type="image/ico" href="' . WEBROOT . 'favicon.ico" />' . LF; } // iPod-Touch/iPhone Icons
public static function config($options) { I18n::$locale = $options['locale']; I18n::loadLocaleFiles(); }
public static function set_locale($locale) { // Reset the translations array I18n::$translations = array(); I18n::$locale = $locale; }
/** * Tries to find a node by the passed $idOrNodeName * * @param integer|string $idOrNodeName * @return Node|boolean */ public function findNode($idOrNodeName, $languageId = null) { $this->depth = 1; $languageId = coalesce(@$languageId, I18n::locale()); if (is_int($idOrNodeName)) { $conditions = array('id' => $idOrNodeName); } else { $conditions = array('NodeText' . ucfirst(substr($languageId, 0, 2)) . '.uri' => DBQuery::quote($idOrNodeName)); } return $this->find(array('conditions' => $conditions)); }
<!DOCTYPE html> <html lang="<?php echo I18n::locale()->getPrimaryLanguage(); ?> "> <head> <meta charset="UTF-8" /> <meta name="description" content="<?php echo __("layout.meta_description"); ?> " /> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" type="text/css" media="all" href="<?php echo Helpers::asset("all.min.css"); ?> " /> <link rel="shortcut icon" href="<?php echo Helpers::asset("images/favicon.ico"); ?> " /> <script type="text/javascript" src="<?php echo Helpers::asset("all.min.js"); ?> "></script> <title> <?php echo $this->title();
/** * Set locale * * <b>Note:</b> This will sequentially call <samp>setlocale(LC_ALL, $locale)</samp> * * @param string Locale in 2-character notation. ie. 'en' or 'sv'. * @return string Old locale or "" if none */ public static function setLocale($locale) { if (self::$locale == $locale) { return $locale; } $old_locale = self::$locale; self::$locale = strtolower(substr($locale, 0, 2)); if ($old_locale) { foreach (self::$domains as $domain) { $domain->freeResources($old_locale); } } setlocale(LC_ALL, $locale); return $old_locale; }
public static function setLocale($locale) { self::$locale = $locale; }
public static function setLocale($locale) { self::$locale = $locale; self::loadArray(); }