How do i do this??
In the constructor of the controller
$this->config->set_item('language', 'pt-br');But didn’t work… any ideas? (Read better the user_guide)
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
November 01, 2007 3:40pm
Subscribe [10]#1 / Nov 01, 2007 3:40pm
How do i do this??
In the constructor of the controller
$this->config->set_item('language', 'pt-br');But didn’t work… any ideas? (Read better the user_guide)
#2 / Nov 01, 2007 10:54pm
what is your language folder called and where is it saved?
#3 / Nov 02, 2007 6:26am
Hello
I have the same problem. I created 3 folders (de, en and fr) in system/language/
When I autoload 1 of the three folders there is no problem. But when i want to change then the language he don’t react on my changes.
I try to change the language (in the views) with this code:
$this->lang->load('site', $headinfo['accountinfo']['language']);In $headinfo[‘accountinfo’][‘language’] is the userlanguage stored (de, en or fr)
My config folder:
$config['language'] = "de";It would be great if someone could help me! Thanks!
#4 / Nov 02, 2007 7:21am
@rafael : have you got an /language/pt-br directory? if it’s easier for you just name it brasilian 😊
@flicker : you have to change the language configuration setting
$this->config->set_item('language', $headinfo['accountinfo']['language']);This should work
#5 / Nov 02, 2007 11:47am
i have the folder called pt-br
i tried in
system/language/pt-br and system/application/language/pt-br, but both didn’t work.
whats the diferrence of brazilian and pt-br? i know that brazil is the only country that speaks “another” kind of portuguese, but don’t matter if is pt-br, brazilian, brazuca, mixugues, or otherelse the name of folder-se!
if i changed “manual” the value from config.php, it works soo fine that i almost cry. but dynamic neither Daileon can resolved!!!!
#6 / Nov 02, 2007 12:37pm
and where or how do you want to use the string?
I don’t know when you make custom files you can depend on the autoloading to load the file, probably you would have to do something like
$this->lang->load('custom_file_lang');
$this->lang->line('showstring');It doesn’t matter if you call it pt-br or brazilian, it’s where you feel most comfortable with.
#7 / Nov 05, 2007 6:29am
allright, but the problem is:
i have the string inside the config.php (the main config file). i didn’t create a custom config file, or my own file. just changed the original, the main, the genesis one!
system/application/config/config.php. So i think that i don’t need to load this, right?
In fact, what i wish is:
The user clicks in link that changes the language of site. And all the language strings are inside another file.
As flicker (the dolphin?) told, the system doesn’t react when i wanna change the $config[‘language’] in runtime.
#8 / Nov 05, 2007 6:43am
I meant by custom files, custom language files.
When the configured language is changed for instance the validation errors show the correct language strings.
I haven’t used custom language files myself because it seems that with language change comes page changes too so i set up separate view directories.
#9 / Nov 05, 2007 6:58am
i didn’t put in different views folders….
just did that:
application/views/hello_view.php
<h1><?=$this->lang->line('hello_title');?></h1>
<?=$this->lang->line('hello_text');?>application/language/pt-br/app_lang.php
$lang['hello_title'] = 'Olá Mundo';
$lang['hello_title'] = 'Esta é uma aplicação padrão, só pra teste';application/language/en/app_lang.php
$lang['hello_title'] = 'Hello World';
$lang['hello_title'] = 'Just testing application, don t worry!';and this is working… but change dynamic don’t 😠
#10 / Nov 05, 2007 7:19am
That is strange. I looked at the validation class and they use
$this->CI->lang->load('validation');to load their language file so i guess you will have to reload your file in your controller after changing the language.
$this->lang->load('app');#11 / Nov 05, 2007 8:05am
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
$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:
$this->lang->load('app', 'pt-br'); //This line in class constructor :blush: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.
#12 / Nov 05, 2007 8:52am
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.
#13 / Nov 05, 2007 10:06am
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.
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!
#14 / Nov 05, 2007 2:43pm
i’ve made an extended language method for switching to another language even if you have autoloaded files
class MY_Language extends CI_Language
{
function MY_Language()
{
parent::CI_Language();
}
function switch_to($idiom)
{
$CI =& get_instance();
$CI->config->set_item('language',$idiom);
$loaded = $this->is_loaded;
$this->is_loaded = array();
foreach($loaded as $lang)
{
$this->load($lang);
}
}
}It’s easier to make multi language sites i think.
I just can’t understand why autoloaded files would have to remain bound to the static language configuration when you switch to another language.
#15 / Dec 25, 2007 3:59pm
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:
function load($langfile = '', $idiom = '', $return = FALSE, $force=false) {
$langfile = str_replace(EXT, '', str_replace('_lang.', '', $langfile)).'_lang'.EXT;
if(!$force){
if (in_array($langfile, $this->is_loaded, TRUE)){
return;
}
}
...
... rest of the method ...
}I’d like a cleaner way of doing this, in fact i propose to do something like this in the future core files. I think its a bug that the class thinks the file is loaded when in fact it is loaded in a different language. (if there’s one thing a language class should do, that would be knowing which language is loaded, not just which file 😊 )
Michaël