Example #1
0
 /**
  * Определение текущей локали по данным HTTP_ACCEPT_LANGUAGE
  * 
  * @return string
  */
 public static function detect_lang()
 {
     $browser_langs = array_keys(Request::accept_lang());
     $lang = array_shift($browser_langs);
     return self::normalize_lang_key($lang);
 }
Example #2
0
 /**
  * Tests Request::accept_lang()
  *
  * @test
  * @covers Request::accept_lang
  * @dataProvider provider_accept_lang
  * @param array $params Query string
  * @param string $expected Expected result
  * @param array $enviroment Set environment
  */
 public function test_accept_lang($params, $expected, $enviroment)
 {
     $this->setEnvironment($enviroment);
     $this->assertEquals($expected, Request::accept_lang($params));
 }
Example #3
0
 * - string   charset     internal character set used for input and output   utf-8
 * - string   cache_dir   set the internal cache directory                   APPPATH/cache
 * - boolean  errors      enable or disable error handling                   TRUE
 * - boolean  profile     enable or disable internal profiling               TRUE
 * - boolean  caching     enable or disable internal caching                 FALSE
 */
Kohana::init(array('base_url' => Kohana::$environment === 'live' ? '/' : '/kohanaphp.com/', 'caching' => Kohana::$environment === 'live', 'profile' => Kohana::$environment !== 'live', 'index_file' => FALSE));
/**
 * Attach the file write to logging. Multiple writers are supported.
 */
Kohana::$log->attach(new Kohana_Log_File(APPPATH . 'logs'));
/**
 * Attach a file reader to config. Multiple readers are supported.
 */
Kohana::$config->attach(new Kohana_Config_File());
$preferred_lang = key(array_intersect_key(Request::accept_lang(), Kohana::config('kohana')->languages));
$preferred_lang = $preferred_lang === NULL ? 'en' : $preferred_lang;
/**
 * Set the routes. Each route must have a minimum of a name, a URI and a set of
 * defaults for the URI.
 */
Route::set('page', '(<lang>(/<action>))', array('lang' => '[a-z]{2}', 'action' => '.+'))->defaults(array('controller' => 'page', 'action' => 'home', 'lang' => $preferred_lang));
/**
 * Execute the main request using PATH_INFO. If no URI source is specified,
 * the URI will be automatically detected.
 */
try {
    $request = Request::instance()->execute();
} catch (Exception $e) {
    // If we are in development and the error wasn't a 404, show the stack trace.
    if (Kohana::$environment == "development" and $e->getCode() != 404) {