1

I have a project going on, and now [admin section is almost done] (I know bit late) I am trying to implement i18n to the project. I think everything works fine except when I enter http://localhost/my_project while my_project is working directory with CI installation in it, I am redirected to the following http://localhost/my_project/enhome (no trailing slash after en) any ideas?

Expecting result http://localhost/my_project/en/home, not just home controller but all controllers are behaving same.

.htaccess, base_url and index_page are set right (all works without the i18n).

routes.php are out of stock

$route['default_controller'] = "home";
$route['404_override'] = '';

// URI like '/en/about' -> use controller 'about'
$route['^(en|de|fr|nl)/(.+)$'] = "$2";

// '/en', '/de', '/fr' and '/nl' URIs -> use default controller
$route['^(en|de|fr|nl)$'] = $route['default_controller'];

edit I am using "new" i18n from I guess ellislab. Sorry for wrong link (for 1.7 CI version).

4

2 回答 2

2

所以经过一番挖掘,我在核心文件中发现了问题,在这个发布的脚本的底部有一个变量$new_url,它在Redirect triggered to http://192.168.1.184/my_project/enhome没有“修复”的情况下回显。我刚刚/在其中添加了它,它工作得很好我想知道这里发生了什么以及这是否OK修复。

function MY_Lang() {
    parent::__construct();

    global $CFG;
    global $URI;
    global $RTR;


    $this->uri = $URI->uri_string();
    $this->default_uri = $RTR->default_controller;

    $uri_segment = $this->get_uri_lang($this->uri);
    $this->lang_code = $uri_segment['lang'] ;

    $url_ok = false;
    if ((!empty($this->lang_code)) && (array_key_exists($this->lang_code, $this->languages)))
    {
        $language = $this->languages[$this->lang_code];
        $CFG->set_item('language', $language);
        $url_ok = true;
    }

    if ((!$url_ok) && (!$this->is_special($uri_segment['parts'][0]))) // special URI -> no redirect
    { 
      // set default language
      $CFG->set_item('language', $this->languages[$this->default_lang()]);

      $uri = (!empty($this->uri)) ? $this->uri: $this->default_uri;
      //OPB - modification to use i18n also without changing the .htaccess (without pretty url) 
      $index_url = empty($CFG->config['index_page']) ? '' : $CFG->config['index_page']."/";
      $new_url = $CFG->config['base_url'].$index_url.$this->default_lang()."/".$uri;
      echo "Redirect triggered to ".$new_url;

      //header("Location: " . $new_url, TRUE, 302);
      // exit;
    }
}
于 2013-06-13T08:56:44.213 回答
0

这个库有点旧,很久没有更新作者了,它适用于 CI 1.7,但这里是与 CI 2.1 兼容的更新版本。* 相同的库,但更新版本的工作方式与你可以从这里下载的相同

CodeIgniter 2.1 国际化 i18n

于 2013-06-12T16:41:01.627 回答