Show
Ignore:
Timestamp:
09/03/2007 09:41:27 PM (15 months ago)
Author:
Shadowhand
Message:

Even better i18n handling, by adding the language segment to the URI

Location:
trunk/modules/user_guide
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/modules/user_guide/controllers/user_guide.php

    r490 r495  
    2121                        ) 
    2222                ); 
     23                 
     24                if ($this->uri->segment(2) == FALSE) 
     25                        url::redirect('user_guide/'.Config::item('core.locale').'/kohana/about'); 
    2326        } 
    2427 
    2528        public function _remap() 
    2629        { 
    27                 $category = strtolower($this->uri->segment(2)); 
    28                 $section  = strtolower($this->uri->segment(3)); 
     30                $language = strtolower($this->uri->segment(2)); 
     31                $category = strtolower($this->uri->segment(3)); 
     32                $section  = strtolower($this->uri->segment(4)); 
    2933 
    3034                // Media resource loading 
    31                 if ($category === 'js' OR $category === 'css') 
     35                if ($language === 'js' OR $language === 'css') 
    3236                { 
    33                         return $this->$category($section); 
     37                        return $this->$language($category); 
     38                } 
     39                elseif ($section == FALSE) 
     40                { 
     41                        url::redirect('user_guide/'.$language.'/kohana/about'); 
    3442                } 
    3543 
    3644                // Set the view that will be loaded 
    3745                $category = ($category == FALSE)  ? 'kohana' : $category; 
    38                 $content  = rtrim('user_guide/'.Config::item('core.locale', TRUE).$category.'/'.$section, '/'); 
     46                $content  = 'user_guide/'.$language.'/'.$category.'/'.$section; 
     47                $content  = rtrim($content, '/'); 
    3948 
    40                 // Display output 
    41                 $this->load->view('user_guide/template', array 
    42                 ( 
    43                         'active_category' => $category, 
    44                         'active_section'  => $section, 
    45                         'content'         => $this->load->view($content)->render(FALSE, array($this, '_tags')) 
    46                 ))->render(TRUE); 
     49                try 
     50                { 
     51                        // Display output 
     52                        $this->load->view('user_guide/template', array 
     53                        ( 
     54                                'category' => $category, 
     55                                'section'  => $section, 
     56                                'language' => $language, 
     57                                'content'  => $this->load->view($content)->render(FALSE, array($this, '_tags')) 
     58                        ))->render(TRUE); 
     59                } 
     60                catch (Kohana_Exception $exception) 
     61                { 
     62                        trigger_error('The Kohana User Guide has not been translated into the requested language.', E_USER_ERROR); 
     63                } 
    4764        } 
    4865 
  • trunk/modules/user_guide/i18n/en/User_guide_menu.php

    r494 r495  
    11<?php defined('SYSPATH') or die('No direct access allowed.'); 
    2 /* $Id: user_guide.php 485 2007-09-04 00:12:20Z Shadowhand $ */ 
    3  
    42/** 
    53* Kohana User Guide Menu 
    6 * Topics in Categories (Eg, General, Libraries) 
    7 * Articles in Sections (Eg, Installation) 
    8 * Libraries and Helpers are in alphabetic order 
    9 * Other Categories are in logical order 
     4*  
     5* Topics in Categories (eg: Kohana, General, Libraries) 
     6* Articles in Sections (eg: Installation, Configuration, Pagination) 
     7* Libraries and helpers are in alphabetical order 
     8* Other categories are in logical order 
     9* 
     10* $Id: user_guide.php 485 2007-09-04 00:12:20Z Shadowhand $ 
    1011*/ 
    1112$lang = array 
  • trunk/modules/user_guide/views/user_guide/template.php

    r494 r495  
    3737<?php 
    3838 
    39 foreach(Kohana::lang('user_guide_menu') as $category => $menu): 
     39foreach(Kohana::lang('user_guide_menu') as $cat => $menu): 
    4040 
    41         $active = (strtolower($category) == $active_category) ? ' active' : ''; 
     41        $active = (strtolower($cat) == $category) ? ' active' : ''; 
    4242 
    4343?> 
    44 <li class="first<?php echo $active ?>"><span><?php echo $category ?></span><ul> 
     44<li class="first<?php echo $active ?>"><span><?php echo $cat ?></span><ul> 
    4545<?php 
    4646 
    47         foreach($menu as $section): 
     47        foreach($menu as $sec): 
    4848 
    49                 $active = (strtolower($section) == $active_section) ? 'lite' : ''; 
     49                $active = (strtolower($sec) == $section) ? 'lite' : ''; 
    5050 
    5151?> 
    52 <li class="<?php echo $active ?>"><?php echo html::anchor(strtolower('user_guide/'.$category.'/'.$section), $section) ?></li> 
     52<li class="<?php echo $active ?>"><?php echo html::anchor(strtolower('user_guide/'.$language.'/'.$cat.'/'.$sec), $sec) ?></li> 
    5353<?php 
    5454 
     
    6565</div> 
    6666<!-- @end Menu --> 
     67 
    6768<!-- @start Body --> 
    6869<div id="body"> 
     
    7071</div> 
    7172<!-- @end Body --> 
     73 
    7274<!-- @start Footer --> 
    7375<div id="footer"><p id="copyright"><?php echo sprintf(Kohana::lang('user_guide.copyright'), date('Y')) ?></p></div>