Change language in config.php dynamic [RESOLVED] |
[eluser]ELRafael[/eluser]
OK. What you told me is not the solution, but clears my brain, thanks!!! What i done wrong: In the config/autoload.php, i had autoloaded the language, in Code: $autoload['language'] = array('app'); So, whatever i change in the controller, don't make any effect. I removed the language in autoload.php and set like that in the controller: Code: $this->lang->load('app', 'pt-br'); //This line in class constructor :) And what's happen? What i wanted!! As i wrote in the first post, the solution was read better the userguide Loading A Language File In order to fetch a line from a particular file you must load the file first. Loading a language file is done with the following code: $this->lang->load('filename', 'language'); Where filename is the name of the file you wish to load (without the file extension), and language is the language set containing it (ie, english). If the second parameter is missing, the default language set in your application/config/config.php file will be used. and Auto-loading Languages If you find that you need a particular language globally throughout your application, you can tell CodeIgniter to auto-load it during system initialization. This is done by opening the application/config/autoload.php file and adding the language(s) to the autoload array.
[eluser]xwero[/eluser]
It doesn't makes much sense that the auto loaded files don't change if you change the language then what is the point of having different directories? so following the user guide you would have to have en_app_lang.php and br-pt_app_lang.php in both directories? With the lang->load method it should be possible to overwrite the autoloaded stings but that doesn't work either. It seems like the autoloading of languages files could need some more work.
[eluser]ELRafael[/eluser]
[quote author="xwero" date="1194288743"]It doesn't makes much sense that the auto loaded files don't change if you change the language then what is the point of having different directories? so following the user guide you would have to have en_app_lang.php and br-pt_app_lang.php in both directories? With the lang->load method it should be possible to overwrite the autoloaded stings but that doesn't work either. It seems like the autoloading of languages files could need some more work.[/quote] so following the user guide you would have to have en_app_lang.php and br-pt_app_lang.php in both directories? NO. The structure is that: system/application/language/en/app_lang.php system/application/language/it/app_lang.php system/application/language/pt-br/app_lang.php one dir for each language. i copy this structure from bambooinvoice. and, to me, is fine! I agree that makes no sense autoload. But worked (thanks God and Daileon). If you wanna see the result (in fact, i'm making this personal app for a future video tutorial), http://projetos.elrafael.net/videos To all that helped, thanks a lot! maybe someday i'll pay a true brazilian beer!
[eluser]xwero[/eluser]
i've made an extended language method for switching to another language even if you have autoloaded files Code: class MY_Language extends CI_Language I just can't understand why autoloaded files would have to remain bound to the static language configuration when you switch to another language.
[eluser]mick_sp[/eluser]
I've been trying to get this to work, but it didn't. Of course extending the core Language-class is de cleanest solution, but when i didn't get that to work (i think there's some $this/$CI mixup in there somewhere) i just added an extra parameter to the Language->load method (i, know, i know, never change the core files) like so: Code: function load($langfile = '', $idiom = '', $return = FALSE, $force=false) { ![]() Michaƫl
[eluser]xwero[/eluser]
@michael : Sorry for the late answer, your post got lost during dinner ![]() I just used it myself and it works great but i added an extra check Code: class MY_Language extends CI_Language i use it as follows Code: // controller
[eluser]Sixer[/eluser]
Thanks for this. Works like a charm. Note: It doesn't work as expected if $this->config->set_item('language','...') is not done before the language switch is used. So set the language in the config using $this->config->set_item() before you attempt to use $this->lang->switch_to().
[eluser]Unknown[/eluser]
I had the same problem and it helped me a log! thanks
[eluser]franboud[/eluser]
Thanks for all the tips! It helped me overcome a problem. Thanks again. |
Welcome Guest, Not a member yet? Register Sign In |