简体   繁体   中英

How to internazionalize a website using Codeigniter

How can i translate my codeigniter website in different languages?

I'm actually using the language class of codeigniter. Once I've created the language files in application/language/language_folder/file_lang.php , how can I switch from a language to another?

I created a file language in Italian & English, but how can I know switch from one to another ?

Can I use a function in the uri when a user set a language?

Language files are always loaded with the filename parameter, but also with the language parameter.

If you write this in your constructor:

$CI =& get_instance();
$CI->load->library('session'); (unless you autoload it)
$CI->language = $CI->session->userdata('lang') ? $CI->session->userdata('lang') : $CI->config->item('default_language');
if($CI->input->get('lang')) 
{
    $CI->session->set_userdata('lang', $CI->input->get('lang'));
} 
$CI->lang->load('file', $CI->session->userdata('lang'));

Then you can switch language just by adding ?lang=folder in your url.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM