2

I am converting a site to multilingual . In this process for automation of conversion i am using language files for like menu,static text etc . I was thinking of merging this methodology to also retrieve content from database based on language .

Like admin is entering multiple content for each language .I tried several things couldnt find way to manage this ...

Here is my code. ....

created a hook ...

$hook['post_controller_constructor'] = array(
    'class' => 'LanguageLoader',
    'function' => 'initialize',
    'filename' => 'LanguageLoader.php',
    'filepath' => 'hooks'
);

and in hooks.php

    class LanguageLoader
{
    function initialize() {
        $ci =& get_instance();
        $ci->load->helper('language');

        $site_lang = $ci->session->userdata('site_lang');

        if ($site_lang) {
            $ci->lang->load('topmenu',$ci->session->userdata('site_lang'));
        } else {
            $ci->lang->load('topmenu','english');
        }
    }
}

and then controller...

class Lang extends MX_Controller {
 public function __construct() {
        parent::__construct();
        $this->load->helper('url');
    }

    function change($language = "") {

        $language = ($language != "") ? $language : "english";
        $this->session->set_userdata('site_lang', $language);
        redirect(base_url());
    }

    function index() {        
        // get partials
      }

}

and simply calling like this ...

<?php echo lang('sign_up')?>

2 Answers 2

4

A bit late, but Language Class Extended DB is a very good solution.

Sign up to request clarification or add additional context in comments.

Comments

0

use in constructor controller

class Service extends CI_Controller {

    public function __construct() { 

        parent::__construct();
        header('Content-Type: application/json; charset=utf-8');   
    }

    public function func1....
    {
        //code 
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.