Welcome Guest, Not a member yet? Register   Sign In
Is my implementation of multi language okay?

Hi guys,

There are so many different ways to add multi-language functionality to a CI installation. I went ahead and put together something that looks like it will work and I would like some feedback.


My website purpose is to sell online English lessons to people in Europe. It is crucial that my site is multilingual.


I use HMVC modules to organize my site... as a result I am unable to implement /en/ or /fr/ urls.

My website has four user areas:

  1. frontend (public access)
  2. student area (login protected)
  3. teacher zone (login protected)
  4. my administration panel
The areas that need multi-lang are the frontend and student area.

Here is what I am doing:

I am storing a users choice in a session variable "language".

The default session language is set to English in the templates __constructor() like this:

PHP Code:
     * handles the default language for the template
   public function __construct()
       // set language
       if ($this->session->userdata('language') === null) {

So when someone requests my home page I call the templates controller and the frontend method.

PHP Code:
     * the public frontend
     * @param array $data
     * @return html
   public function frontend($data)
       // get template language

       // load template

So my language translations are of course in the Application->language folder... here is how I have it structured:


Because there is actually quite a bit of language that needs to be translated (e.g. footer, form validation, actual content and paragraphs, menus, blurbs) I was thinking of splitting up the translations to different files such as frontend/footer_lang.php, frontend/header_lang.php etc... and then including them all into a master "frontend_lang.php"... is that a good idea?

As for the actual implementation of the language switcher... I have a dropdown menu with my different language options:


So when a user selects 'french' for example, they get redirected to base_url/language/switch_language/french controller that looks like this:

PHP Code:
class Language extends MX_Controller
    public function switch_language($language)

So basically I am just setting the user language session variable and redirecting to the last url page they were on.

I am interested to hear some feedback on my solution.

Many thanks.


Attached Files Thumbnail(s)

Theme © iAndrew 2016 - Forum software by © MyBB