本文整理汇总了PHP中I18n::lang方法的典型用法代码示例。如果您正苦于以下问题:PHP I18n::lang方法的具体用法?PHP I18n::lang怎么用?PHP I18n::lang使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类I18n
的用法示例。
在下文中一共展示了I18n::lang方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: before
/**
* @throws HTTP_Exception_401
* @since 1.0
*/
public function before()
{
parent::before();
// Check request signature
if (Kohana::$config->load('hapi.require_signature') && !HAPI_Security::is_request_signature_valid($this->request)) {
HAPI_Security::require_auth('Request signature was invalid');
}
// Login using basic auth
if (array_key_exists('authorization', $this->request->headers())) {
HAPI_Security::login($this->request->headers('authorization'));
}
// Check that user is authenticated
if ($this->_require_login && !HAPI_Security::is_request_authenticated($this->request)) {
HAPI_Security::require_auth();
}
// Instantiate the encoder object for the response (based on the Accept header)
$this->response_encoder = $this->_get_response_encoder();
// Set current language
$supported_languages = Kohana::$config->load('hapi.supported_languages');
$preferred_language = $this->request->headers()->preferred_language($supported_languages);
if ($preferred_language) {
I18n::lang($preferred_language);
}
$extract_array = function ($keys) {
if (empty($keys)) {
return [];
}
return explode(',', $keys);
};
// Filter response keys
$this->_paths = $extract_array($this->request->query('paths'));
}
示例2: before
public function before()
{
parent::before();
I18n::lang('ru');
//Cookie::$salt = 'assfr423dsf';
Session::$default = 'cookie';
$this->cache = Cache::instance('file');
$this->auth = Auth::instance();
$this->user = $this->auth->get_user();
$this->session = Session::instance();
$site_name = Kohana::$config->load('myconf.site_name');
$site_description = Kohana::$config->load('myconf.site_description');
$footer = Kohana::$config->load('myconf.footer');
//Вывод в шаблон
$this->template->site_name = $site_name;
$this->template->site_description = $site_description;
$this->template->page_title = null;
$this->template->page_footer = $footer;
//Подключение стилий и скриптов
$this->template->styles = array('');
$this->template->scripts = array();
//Подключаем блоки
$this->template->block_left = null;
$this->template->block_center = null;
$this->template->block_right = null;
$this->template->block_headerRight = null;
}
示例3: before
public function before()
{
parent::before();
$lang = $this->request->param('lang');
// Make sure we have a valid language
if (!in_array($lang, array_keys(Kohana::config('kohana')->languages))) {
$this->request->action = 'error';
throw new Kohana_Request_Exception('Unable to find a route to match the URI: :uri (specified language was not found in config)', array(':uri' => $this->request->uri));
}
I18n::$lang = $lang;
if (isset($this->page_titles[$this->request->action])) {
// Use the defined page title
$title = $this->page_titles[$this->request->action];
} else {
// Use the page name as the title
$title = ucwords(str_replace('_', ' ', $this->request->action));
}
$this->template->title = $title;
if (!kohana::find_file('views', 'pages/' . $this->request->action)) {
$this->request->action = 'error';
}
$this->template->content = View::factory('pages/' . $this->request->action);
$this->template->set_global('request', $this->request);
$this->template->meta_tags = array();
}
示例4: before
public function before()
{
parent::before();
// Borrowed from userguide
if (isset($_GET['lang'])) {
$lang = $_GET['lang'];
// Make sure the translations is valid
$translations = Kohana::message('langify', 'translations');
if (in_array($lang, array_keys($translations))) {
// Set the language cookie
Cookie::set('langify_language', $lang, Date::YEAR);
}
// Reload the page
$this->request->redirect($this->request->uri());
}
// Set the translation language
I18n::$lang = Cookie::get('langify_language', Kohana::config('langify')->lang);
// Borrowed from Vendo
// Automaticly load a view class based on action.
$view_name = $this->view_prefix . Request::current()->action();
if (Kohana::find_file('classes', strtolower(str_replace('_', '/', $view_name)))) {
$this->view = new $view_name();
$this->view->set('version', $this->version);
}
}
示例5: before
public function before()
{
I18n::lang('pl-pl');
$this->session = Session::instance();
if ($this->auto_render === TRUE and $this->template !== NULL and !in_array($this->request->action, $this->no_view)) {
if (!in_array($this->request->action, $this->no_template)) {
$this->template = new View((!empty($this->request->directory) ? $this->request->directory . '/' : NULL) . $this->template);
if (Request::$is_ajax) {
$this->template = new View('common/ajax');
}
if ($this->content === TRUE) {
$this->template->content = new View((!empty($this->request->directory) ? $this->request->directory . '/' : NULL) . $this->request->controller . '/' . $this->request->action);
$this->content =& $this->template->content;
}
} else {
if ($this->content === TRUE) {
$this->content = new View((!empty($this->request->directory) ? $this->request->directory . '/' : NULL) . $this->request->controller . '/' . $this->request->action);
}
$this->template =& $this->content;
if (Request::$is_ajax) {
$this->template = new View('common/ajax');
$this->template->content = $this->content;
}
}
}
}
示例6: before
public function before()
{
$this->session = Session::instance();
$this->config = Kohana::$config->load('settings');
$this->language = Lang::get_accepted_language($this->config->language);
/**
* Sets the default timezone used by all date/time functions
*
* @link http://kohanaframework.org/guide/using.configuration
* @link http://www.php.net/manual/timezones
*/
date_default_timezone_set($this->config->timezone);
/**
* Set locale information
*
* @link http://kohanaframework.org/guide/using.configuration
* @link http://www.php.net/manual/function.setlocale
*/
setlocale(LC_ALL, $this->config->languages[$this->language] . '.' . Kohana::$charset);
/**
* Set app language
* Provides loading of language and translation
*/
I18n::lang($this->language);
}
示例7: setup
public static function setup()
{
language::$available_languages = Kohana::config('locale.languages');
if (Router::$language === NULL) {
$redirect = NULL;
if (empty(Router::$current_uri)) {
if (($lang = language::browser_language()) !== '') {
$redirect = $lang;
} else {
reset(language::$available_languages);
$redirect = key(language::$available_languages);
}
} else {
if (($lang = language::browser_language()) !== '') {
$redirect = $lang . '/' . Router::$current_uri;
} else {
reset(language::$available_languages);
$redirect = key(language::$available_languages) . '/' . Router::$current_uri;
}
}
url::redirect($redirect);
}
Kohana::config_set('locale.language', language::$available_languages[Router::$language]['language']);
I18n::$lang = language::$available_languages[Router::$language]['language'][0];
}
示例8: before
public function before()
{
if ($this->request->action === 'media') {
// Do not template media files
$this->auto_render = FALSE;
} else {
// Grab the necessary routes
$this->media = Route::get('docs/media');
$this->api = Route::get('docs/api');
$this->guide = Route::get('docs/guide');
if (isset($_GET['lang'])) {
$lang = $_GET['lang'];
// Load the accepted language list
$translations = array_keys(Kohana::message('userguide', 'translations'));
if (in_array($lang, $translations)) {
// Set the language cookie
Cookie::set('userguide_language', $lang, Date::YEAR);
}
// Reload the page
$this->request->redirect($this->request->uri);
}
// Set the translation language
I18n::$lang = Cookie::get('userguide_language', Kohana::config('userguide')->lang);
// Use customized Markdown parser
define('MARKDOWN_PARSER_CLASS', 'Kodoc_Markdown');
// Load Markdown support
require Kohana::find_file('vendor', 'markdown/markdown');
// Set the base URL for links and images
Kodoc_Markdown::$base_url = URL::site($this->guide->uri()) . '/';
Kodoc_Markdown::$image_url = URL::site($this->media->uri()) . '/';
}
parent::before();
}
示例9: lang
public static function lang($lang = NULL)
{
if ($lang) {
I18n::$lang = strtolower(str_replace(array(' ', '_'), '-', $lang));
}
return I18n::$lang;
}
示例10: action_index2
public function action_index2()
{
I18n::lang('ru');
// echo __('Hello, world!');
$username = 'Гость';
echo __('Hello, :user', array(':user' => $username));
}
示例11: before
public function before()
{
parent::before();
// Load the configuration settings
$config = $this->_config = Kohana::config('docs')->as_array();
// The language is part of the route
if ($lang = $this->request->param('lang'))
{
// Set the language and locale
I18n::lang($lang);
setlocale(LC_ALL, $config['language']['supported'][$lang]['locale']);
// Remember the preferred language
Cookie::set('lang', $this->lang = $lang);
}
else
{
// We need a language, try the cookie or use the default
$lang = Cookie::get('lang', $config['language']['default']);
// Redirect with a chosen language
$this->request->redirect($this->request->uri(array('lang' => $lang)));
}
}
示例12: init
/**
* Application initialization
* - Loads the plugins
* - Sets the cookie configuration
*/
public static function init()
{
// Set defaule cache configuration
Cache::$default = Kohana::$config->load('site')->get('default_cache');
try {
$cache = Cache::instance()->get('dummy' . rand(0, 99));
} catch (Exception $e) {
// Use the dummy driver
Cache::$default = 'dummy';
}
// Load the plugins
Swiftriver_Plugins::load();
// Add the current default theme to the list of modules
$theme = Swiftriver::get_setting('site_theme');
if (isset($theme) and $theme != "default") {
Kohana::modules(array_merge(array('themes/' . $theme->value => THEMEPATH . $theme->value), Kohana::modules()));
}
// Clean up
unset($active_plugins, $theme);
// Load the cookie configuration
$cookie_config = Kohana::$config->load('cookie');
Cookie::$httponly = TRUE;
Cookie::$salt = $cookie_config->get('salt', Swiftriver::DEFAULT_COOKIE_SALT);
Cookie::$domain = $cookie_config->get('domain') or '';
Cookie::$secure = $cookie_config->get('secure') or FALSE;
Cookie::$expiration = $cookie_config->get('expiration') or 0;
// Set the default site locale
I18n::$lang = Swiftriver::get_setting('site_locale');
}
示例13: before
public function before()
{
parent::before();
I18n::lang('ru');
Cookie::$salt = 'eqw67dakbs';
Session::$default = 'cookie';
//$this->cache = Cache::instance('file');
$this->session = Session::instance();
$this->auth = Auth::instance();
$this->user = $this->auth->get_user();
// $captcha = Captcha::instance();
// Подключаем стили и скрипты
$this->template->styles = array();
$this->template->scripts = array();
//Вывод в шаблон
$this->template->title = null;
$this->template->site_name = null;
$this->template->description = null;
$this->template->page_title = null;
//Подключаем главный шаблон
$this->template->main = null;
$this->template->userarea = null;
$this->template->top_menu = View::factory('v_top_menu');
$this->template->manufactures = null;
$this->template->left_categories = null;
$this->template->slider_banner = null;
$this->template->block_left = array();
$this->template->block_center = array();
$this->template->block_right = array();
$this->template->block_footer = null;
}
示例14: __isset
public function __isset($column)
{
if (in_array($column, $this->_i18n_fields)) {
$column .= '_' . I18n::lang();
}
return parent::__isset($column);
}
示例15: initialize
/**
*
* 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);
}
}