Language selection problem |
[eluser]Unknown[/eluser]
Hi, i want make multi-lang with CI but... if i change language ($this->config->set_item('language', 'french') in MY_Controller, the language file in autoload.php is loaded with default language folder ($config['language'] in config.php) ! Need help *and i dont find solution or good exemple to make multi-language in CI manuel Thx happy christmas and new year
[eluser]Joseph Wensley[/eluser]
Instead of autoloading you could use $this->lang->load('filename', 'lang');
[eluser]pickupman[/eluser]
[quote author="Joseph Wensley" date="1292624535"]Instead of autoloading you could use $this->lang->load('filename', 'lang');[/quote] To be a little more complete: Code: class MY_Controller extends Controller{
[eluser]jmadsen[/eluser]
You don't need: <code>$language = (!empty($language)) ? $language : 'english'; //set fallback to english to next line doesn't break</code> "If the second parameter is missing, the default language set in your application/config/config.php file will be used." This also include the variable being empty or and invalid language code. Just set English in your config as the default.
[eluser]tomcode[/eluser]
I use Code: $this->config->set_item('language', $my_language); to set the app's language before loading any language files. I usually set it in MY_Controller, a hook would do the job, too. A solution for international sites used to be : I18n on the Wiki Personally I use a solution very close to i18n, I do not override the helper functions and have some other tweaks Watch out when loading files using Code: $this->load->lang('filename', $language); For complex projects with loads of entries : - I organise my language idents like URI's, using a point as segment separator - I use conventions like adding _fmt to an ident when it used with sprintf() - I override CI's lang->line() method to have it return the identifier when the entry is not found, very nice for debugging and allows to worry for translations later : Code: /**
[eluser]Unknown[/eluser]
Hello, Ok ! Code: /** Thx all bye |
Welcome Guest, Not a member yet? Register Sign In |