Welcome Guest, Not a member yet? Register   Sign In
Multilingual site using database rather than language files.

[eluser]mercy loving criminal[/eluser]
Hi all

Having done some initial searching on this topic, I've not managed to uncover a simple answer, so wanted to check here and see if anyone else has come across this...

I am working on a multilingual, codeigniter based site, but would prefer to store language variations in the database rather than language files. Eventually I would like certain labels etc to be translated by volunteer community members into their own languages, and therefore would prefer for multilingual labels/content to be stored in a database rather than files.

Does anybody have experience of this, or any advice/pointers? Can I achieve what I want just by using language files?

Thanks for your help,


Well, for one thing, if you are storing everything in the database you will have LOTS of database requests. So you'll need some good caching to make that work. Apart from that, I don't think there is a big difference; CI's language system is also just a big list of key/values.

For labels you can use something like this:
// load this inside a Base_Controller like MY_Controller
// assume that $lang_id = 1 is english (the default language)
// assume that $lang_id > 1 is any other language you might support
    protected function set_labels()

        // load standard english labels so we don't have empty labels:
        $all_labels = $this->label_model->get_labels(1);
        $this->label = ($this->lang_id == 1) ? $all_labels : array_merge((array)$all_labels, (array)$this->label_model->get_labels($this->lang_id));

        //make labels available to all views
        $this->load->vars('label', (object) $this->label);

This way your labels will be available in your controller as $this->label->... and inside your views as $label->...


And that is already quite slow. I've added some benchmarking to my $this->lang->line() method, and it shows that a third of the processing time of a page goes to calls to this method (an average page calls this method a few hundered times...).

A better (= more scalable) language system is high on my "have to do something clever here but I still haven't got a clue what" list...

[eluser]mercy loving criminal[/eluser]

Might think this one through a little more, but if you have other thoughts and ideas, would love to hear them!


It will make a lot faster if each language will be save in different table. eg tbl_english, tbl_spanish, tbl_chinese and a header table which holds the token(keyword) for each lang.

But, I would like to suggest to save it in a flat file or continue the CI Language. Storing multiple language in database will make it slow versus flat file.

Theme © iAndrew 2016 - Forum software by © MyBB