1
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ This question resulted in this commit \$\endgroup\$
    – germanosk
    Nov 17, 2016 at 21:58

1 Answer 1

1
\$\begingroup\$

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.

If you always used this format for loading language:

$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).

\$\endgroup\$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.