Building multi language website

2»

Comments

  • edited June 2011
    damn, i'm sure i followed all of the above but when i hit save on a page the page_variables table is always empty... what am I doing wrong??

    EDIT: i think i got it. If you set the lang_id field as an int, make sure the languages array in your config has a numerical id as key:

    $languages = array('0' => 'English', '1' => 'German');

    and not like in @admin 's example:

    1. Create a config file or table to contain the language options (e.g. $config['languages'] = array('english' => 'English', 'spanish' => 'Spanish')... )
  • edited 10:01PM
    The advice from all who have contributed on this page has been invaluable, although I'm kind of disappointed to see this isn't part of the core of FuelCMS yet. For me, this is one of the basic features of a modern CMS.

    Anyway, I've been hacking around for the better part of a day trying to get it to work and I'm slowly getting there. For anyone who is wondering, the line that needs altering to stop the page variables in one language overwriting the page variables of another, this is within the _save_page_vars method within the page controller on around about line 350 (in the version that I'm using).

    It would be good to know what future plans are for multi-language support - if I have to hack these changes into every future version of the CMS it's going to be a real pain.
  • edited 10:01PM
    Not sure if this will help anyone, as perhaps my case is a little unusual. I've integrated fuelCMS with an existing CI app that was using the i18n class to serve multilingual content depending on the first slug in the URI. So the i18n class basically matches the slug to a language - so I have an array like this in my config file:
    $config['lang_uri_abbr'] = array("ja" => "japanese", "en" => "english");
    The i18n class grabs the slug from the URL and loads the relevant language files for my view.

    However, as pierlo points out above, for some reason it doesn't work if you set the lang_id as a varchar in the fuel_pages_variables table. I tracked down the cause to the find_all() method in core/MY_Model.php but didn't feel like working out why it didn't work.
    So, since I had to set the lang_id field to int to get it to work, I needed two ways to get it to load - one for the front end and one for the backend.
    Since on the front end the language is loaded as a string (ie. $config['language'] = "english") and fuelCMS needed a numeric id, I did the following.
    First in application/config/config.php
    // This is for FuelCMS admin menus $config['languages'] = array(0 => 'english', 1 => 'japanese'); // This is for converting from string to numeric $config['lang_to_id'] = array('english' => 0, 'japanese' => 1);

    Then in the fuel/modules/fuel/models/pagevariables_model.php file, I changed the _common_query() method to the following.

    function _common_query() { $this->db->join($this->_tables['pages'], $this->_tables['pages'].'.id = '.$this->_tables['pagevars'].'.page_id', 'left'); $myuri_path = $_SERVER['REQUEST_URI']; $myuri_path = strpos($myuri_path,'fuel/pages'); // Check to see if page loaded from admin or front end. The following is executed if loaded from the front end. if(!$myuri_path){ $CI =& get_instance(); $language = $CI->config->item('language'); $lang_ids = $CI->config->item('lang_to_id'); $lang_id = $lang_ids[$language]; $this->db->where(array('lang_id' => $lang_id)); } }

    This is a nasty hack and you probably won't need it if you start with FuelCMS from the beginning rather than trying to integrate it into an existing project, but it works for me :)
  • edited 10:01PM
    Hi all,

    This is a great thread and I've made good progress on the backend (admin's 6 steps were very clear), but I'm still struggling on the front end, specifically in regards to language integration in location/slug (as in www.site.com/en/page)?

    I'm having trouble understanding webcam's approach. The "aha!" moment is still elusive. Can webcam or someone else who has succeeded in implementing this re-explain differently the streps taken?

    This would be very much appreciated as multi-language support is the only thing stopping me from fully commiting to Fuel CMS for my next sites (and I really want to use Fuel CMS).

    Thanks!
  • edited 10:01PM
    I found some stuff in this front end library to be helpful for detecting the appropriate language to serve up.
    http://codeigniter.com/wiki/Language_Selection_2

    It looks at the URI segment, then a cookie value, then checks the accept header value to set the language config value.
  • edited 10:01PM
    What does Erik mean by...
    ----------------------------------------------
    I changed
    UNIQUE KEY `page_id` (`page_id`,`name`)
    to
    UNIQUE KEY `page_id` (`page_id`,`name`,`lang_id`)
    ----------------------------------------------
    ?

    Plus, I've implemented your 6 step approach, admin, for the backend (including Erik's code corrections). It works but I get this PHP error when editing pages:

    Message: Undefined property: Pages::$lang_id
    Filename: core/Model.php
    Line Number: 50

    Any idea why this is happening?

    (sorry if it's a newbie question)
  • edited 10:01PM
    The unique key is referencing the unique key index that is applied to the pages table. With regards to the error, what happens if you change the code in step 4 to use $CI instead of $this:
    $save = array('page_id' => $id, 'name' => $key, 'value' => $value, 'type' => $val['type'], 'lang_id' => $CI->input->post('lang_id');
  • edited May 2012
    Using $CI, I get "Undefined variable: CI" when I try to save.

    When I use $this, the "Undefined property: Pages::$lang_id" error is also thrown when I navigate to a page.

    I'll go through the process again, I must've done something wrong...
  • edited 10:01PM
    Put above it $CI =& get_instance();
Sign In or Register to comment.