ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Multilingual i18n enviroment for CodeIgniter

October 01, 2012 9:41am

Subscribe [10]
  • #1 / Oct 01, 2012 9:41am

    keevitaja

    107 posts

    Hi,

    i just wrote Multilingual i18n enviroment for CodeIgniter
    Differences from other similar is: language segment for the default languge can be hidden by configuration.

    https://github.com/keevitaja/mci-codeigniter

    Demo: http://mci.vebia.ee/

  • #2 / Oct 29, 2012 5:48pm

    Volder

    27 posts

    I’m struggling with the routing problem.

    I want that default index() method would be used for Category controller, e.g:

    if I visit mysite.com/category/2 I want controller “Category” to be invoked, function index() with a passed argument 2.

    For this I usually write in routes the rule:

    $route['category/(:num)'] = "category/index/$1";

    Now as I use multilingual I want also the following URL to go same path:
    mysite.com/en/category/2
    So I want controller Category to be invoked function index() with 2 passed as argument.

    As I have in my routes file before the previous rule the following:

    $route['^(en|de|fr|it)/(.+)$'] = "$2";
    $route['^(en|de|fr|it)$'] = $route['default_controller'];

    I assume that the rule about “index” before should give the same result as the rules in routes are executed in the order of appearence. And when the last rule reached the url is already cleaned from language component. But that’s not working and I get 404 error page.
    Any ideas?

    PS
    The whole routes now:

    $route['default_controller'] = "main";
    $route['404_override'] = '';
    
    // All re-mappings must begin with '^(en|et|ru)' !!!
    
    $route['^(en|de|fr|it)/(.+)$'] = "$2";
    $route['^(en|de|fr|it)$'] = $route['default_controller'];
    
    // readdress category and subcategory pages - to index controller
    $route['category/(:num)'] = "category/index/$1";
  • #3 / Oct 30, 2012 4:49am

    keevitaja

    107 posts

    don’t have time to test it, but this should work:

    $route['^((en|de|fr|it)/)?category/(.+)$'] = "category/index/$3";
  • #4 / Oct 30, 2012 5:32am

    Volder

    27 posts

    Thanks it worked. But the idea was to put it before all the general multilingual rules, otherwise it doesn’t work.

    I mistakenly thought that in the routes files all the rules are evaluated one by one. But it is not so. When the engine meets the first rule that applies, it basically doesn’t look at the rest.

    Thanks!

  • #5 / Oct 30, 2012 7:34am

    umefarooq

    690 posts

    really nice library, is there any way we can hide all language from url after switching to other language. same like default language.

  • #6 / Nov 19, 2012 7:41pm

    tiborlovas

    3 posts

    Hello,
    I’m using a _remap function in the controller, and if there is an url without language code, I’m getting a 404_error.

    For example:
    localhost/mysite/en/controller - works
    localhost/mysite/en/ - works
    localhost/mysite/controller - doesnt’ work (getting a 404 page)

    Here are the __construct and _remap part of my controller:
    public function __construct()
    {
    parent::__construct();

    $this->load->language('mci');
    }
    public function _remap($method, $params = array())
    {
    $this->load->model('links');
    $this->load->library('form_validation');
    $this->load->helper(array('url'));
    $data['i18n'] = $this->lang->mci_current();

    $links['links'] = $this->links->get_links();
    $data['menu'] = $this->load->view('link_list', $links, true);
    if($method=="index") $method = "rolunk";
    $data['title'] = lang($method.'.title');
    $data['content'] = lang($method.'.content');

    if (method_exists($this, $method))
    {
    return $this->$method($data, $params);
    }
          $this->error_404($data);
      }

    My routes.php:
    $route[‘default_controller’] = “page”;
    $route[‘404_override’] = ‘page/error404’;

    // URI like ‘/en/about’ -> use controller ‘about’
    $route[’^(hu|en|de)/(.+)$’] = “page/$2”;

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

  • #7 / Nov 21, 2012 3:24am

    keevitaja

    107 posts

    it should be routing problem, please see my previous note:

    http://ellislab.com/forums/viewthread/225196/#1038110

  • #8 / Nov 21, 2012 8:13am

    tiborlovas

    3 posts

    I changed the next line
    $route[’^(hu|en|de)/(.+)$’] = “page/$2”;
    to
    $route[’^((hu|en|de)/)?(.+)$’] = “page/$2”;

    Still doesn’t run :(

  • #9 / Nov 21, 2012 8:16am

    tiborlovas

    3 posts

    Great, I found the solution in this:
    $route[’^((hu|en|de)/)?(.+)$’] = “page/$3”;

    Thank you much! 😊

  • #10 / Nov 21, 2012 11:40am

    keevitaja

    107 posts

    really nice library, is there any way we can hide all language from url after switching to other language. same like default language.

    with this approach no. you have to store the language information somewhere. my solution stores the language in url, other option would be cookie or session but it is highly unrecommended due to SEO issues. one url can’t have multiple content.

  • #11 / Nov 28, 2012 3:20am

    Hamed

    41 posts

    I like this lib.
    I think there is some problem with default language.

  • #12 / Nov 30, 2012 12:28pm

    keevitaja

    107 posts

    according to best of my knowledge default language is “problem free”.

    can you explain the problem?

  • #13 / Nov 30, 2012 12:41pm

    Hamed

    41 posts

    When I open my page and I don’t use site_url() I have problem.
    It redirect me to root controller.

  • #14 / Nov 30, 2012 12:53pm

    keevitaja

    107 posts

    still do not get it. sure it is multilingual problem. paste some code and explain some more.

  • #15 / Nov 30, 2012 12:55pm

    Hamed

    41 posts

    Now I am working on new script let check it again, I hope it works fine.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases