How do I use CodeIgniter to make a double language site/application taking data from MySQL
How do I work with languages in CodeIgniter? Is it really already an intern开发者_Python百科al resource (a helper or library) or I need an plugin to make it work? Or it is so simple that I can't believe (or dumb enough not to)?
Just follow this url Codeigniter's language class
Documentation of CI
is very good, it will teach you everything in a very simple and elegent way.
Two ways: the integrated one and the prettier one, that is not always possible to use.
If you have a server that is not multithreaded on the PHP (in example if you use PHP-FPM), you could use the popular gettext that makes it very easy to translate strings with applications like PoEdit or online free translation webapps like Transifex.
The code is what follows turns on gettext. Put it somewhere before the controller. In the controller constructor is good enough.
// get the current language code
$locale = get_setting('fs_gen_lang');
putenv("LANG=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain("default", FCPATH . "assets/locale");
textdomain("default");
Then you'd have a folder like this:
/my_ci_app/assets/locale/en_UK/LC_MESSAGES/default.po
/my_ci_app/assets/locale/en_UK/LC_MESSAGES/default.mo
and maybe also a base file from which you will base translations come from and that on update will update all other translations. I leave it in:
/my_ci_app/assets/locale/default.pot
Else, you can use the inbuilt language system, that works with strings and arrays. In my opinion, it can end up being a pain to use, but it might be just enough if you don't have many strings in your software. There's also sites that help translating in this way, as CodeIgniter itself does.
Just follow the instructions in the language library and the (probably unnecessary) helper:
http://ellislab.com/codeigniter/user_guide/libraries/language.html
http://ellislab.com/codeigniter/user_guide/helpers/language_helper.html
精彩评论