I am wondering about CI best practices
I need to have some code that detects the browser’s language and assigns the appropriate language file.
does such code belongs under library or helper? ( if i am right helpers are php functions as opposed to libraries which are classes )
also what would be the best way to launch a class as opposed to just load it.
thank you.
You can get language information from a browser with:
Mine returns
en-US,en;q=0.8so you will need to do some parsing to translate that into something useful to you.But then you can set the language which CI uses to load language files with
where ‘english’ is the name of the folder in your
application/languagesfolder which contains your language files.You can do those things anywhere before your code runs. I’d recommend making a
application/libraries/MY_Lang.php(application/core/MY_Lang.php in 2.0) and putting it in the constructor, cos then its always loaded before you use a language file.Lastly should read this. But basically you retrieve a line from your language file with: