Welcome Guest, Not a member yet? Register   Sign In
issue with language and config for internationalization
#1

[eluser]mambe churchill nanje[/eluser]
ok I have this little problem I want to internationalize www.villagediary.org, I wish to setup a session variable called "language", then I use that variable to dynamically change th $config['language'] in the application/config/config.php , these way I know that when a user selects another language like on facebook, and i change the session variable, it will automatically load the files for that language unless they don't exist which will throw an exception
can someone point me to forum topics or tutorials that have achieved this. I don't want to reinvent the wheel.
regards
#2

[eluser]Natebot[/eluser]
Quote:Setting a Config Item

If you would like to dynamically set a config item or change an existing one, you can so using:
Code:
$this->config->set_item('item_name', 'item_value');

Where item_name is the $config array index you want to change, and item_value is its value.

reference: http://ellislab.com/codeigniter/user-gui...onfig.html

[edit:] er, or did you mean how write and read the sessions?
#3

[eluser]mambe churchill nanje[/eluser]
thanks Natebot
thats exactly what I saw in the user guide but one problem I have is that, if the language is dynamically detected from user http headers and then set to session, before the session loads, the config has already loaded, and the default language loaded too, now is it possible to reset the config and then reload the config with all the language settings ???
thats where I have a problem now
#4

[eluser]TheFuzzy0ne[/eluser]
You say the language files are already loaded. What is loading them? Unless you've set a particular language to auto load, a language shouldn't be loaded until you do it manually.
#5

[eluser]mambe churchill nanje[/eluser]
looking at the Controller class in system/libraries I realised Codeigniter loads the config then the language files before even instantiating the controllers,
I could be wrong though
#6

[eluser]TheFuzzy0ne[/eluser]
CodeIgniter has some basic language files, which are for things such as validation messages, database error messages, profiler messages and several other things, however, you can load your own language files whenever you want, and they will be available to you. If I recall correctly, you can even switch between languages, as loading a new language overwrites any identical entries in the $lang array.

So basically, as long as you figure out what file you need to load before you load it, you shouldn't have any problems. You just need to figure out how how you are going to get CodeIgniter to do what you want it to.

I would suggest extending the CI_Controller class, and adding a method called _set_lang(),(the underscore make the function inaccessible via the URI), or similar, which will set the default language. Then you are free to load specific language files from within your controller as you need them.

Hope this helps. Smile
#7

[eluser]mambe churchill nanje[/eluser]
I figured out that one very well, my problem is, when I switch the language say from english to french, the CI basic language files for vallidation, database errors and profiler should also switch and show the version in french instead of english. I am thinking if I can switch the language the reload these basic files. that is where I am stuck
#8

[eluser]TheFuzzy0ne[/eluser]
Your function should override the configured lang variable. As far as I am aware, none of those lang files are loaded until the controller has fully instantiated and has a method called. I think at the very worst, you might get a message in English if your database configuration is incorrect, but that should be all, and you'd only see the message from the first time you run CodeIgniter until you set the correct database config information.

If you really, really want to avoid that, [url="http://ellislab.com/codeigniter/user-guide/general/hooks.html"]hooks[/url] may be the answer.
#9

[eluser]mambe churchill nanje[/eluser]
ok thanks for all the help, I will use kohana and try to use their in built internationalisation pack,




Theme © iAndrew 2016 - Forum software by © MyBB