# A localization helper in codeigniter

I created a project to better understand CI3, while developing it I tried to introduce localization elements.
When I tried to localize the view everything messed up. I made a helper to identify if the user choose a language different than default language then load the right language.

function lang_load($lang_file) { if($this->session->get_userdata('language'))
{
$this->lang->load($lang_file,$this->session->get_userdata('language')); }else {$this->lang->load($lang_file); } }  so everytime instead use $this->lang->load($lang_file);  I use lang_load($lang_file)


I use it on Controllers and in the Views, but I guess it is breaking the MVC principle when used on view side.

• This question resulted in this commit – germanosk Nov 17 '16 at 21:58

This is pretty trivial example for review, but you are right to question use of this function from within a view.

Personally I think this is information that needs to be determined upstream of this decision point, making the function unnecessary.

$this->lang->load($lang_file, $lang);  where $lang here could be a variable, constant, call to static class method, or some other way to get to the current language preference (with this preference determined somewhere outside the logic for actually loading the localization).