Welcome Guest, Not a member yet? Register   Sign In
New here. Need some help with languages
#1

[eluser]Neil_W[/eluser]
Hello,
I'm just getting started with CI and am converting my existing site. My site supports about 15 or so languages and this is currently done via a cookie storing the language code, which then picks the associative array storing the strings - which isn't too dis-similar to the way the language system works in CI.

However, what's missing in CI is this initial retrieval of the current language in the cookie.

As far as I can see there are a few ways and wanted some opinions:

1. Add a hook to the pre_controller and retrieve the cookie if not set
2. Extend the language class to retrieve the cookie in the constructor if not already set
3. Write a new custom library that retrieves cookies into an array (using a key for the cookie name) that could then be run as an autoloaded library

I assumed I'd add this to either a global or a custom config value (or a method if option 3 used).

Thanks for any response.

btw, I checked out the language plugins available (e.g. the one that embeds the language code in the url) but didn't like them. I simply want the best approach to reading/storing a cookie on startup so I can populate the data array.
#2

[eluser]jpi[/eluser]
Hi,

I have used a pre_controller hook in my last project. It worked well. I only faced a little problem : I was auto loading a library which needed some language information (mainly strings dealing with form_validation), but the pre_controller hook was not executed yet. In other words, don't forget that pre_controller hook comes after autoloading.

Anyway, hooks are a bit expensive in term of performance. So if this is the only hook needed, my advice is not to activate hook at all and go for solution 2 or 3.
#3

[eluser]Neil_W[/eluser]
Thanks. Is there some documentation stating the sequence of calls in CI? I can see the top level design showing controllers/filtering/cache/etc but not the order of when helpers, libraries, config, custom files, etc are loaded. This would be handy.

But You've just made me have a horrible thought. I was planning on making use of the cache, but with a language cookie altering the content I can't see how I can do this.

Assuming it comes before caching is checked, perhaps I could inject the language code into the url?
#4

[eluser]danmontgomery[/eluser]
http://ellislab.com/codeigniter/user-gui...pflow.html
#5

[eluser]Neil_W[/eluser]
Hello,
Yes, that's the diagram I referred to as already reading. I was after something more indepth without having to read all the code like the above example knowing that precontroller hook comes after autoloading, etc.

Let's not digress, I'm still after guidance on my original question Smile




Theme © iAndrew 2016 - Forum software by © MyBB