In this paper, an example is given to describe the CodeIgniter implementation of config control based on browser language automatic conversion function, for Web site development is very practical.
The specific method of operation is as follows:
The language pack file is as follows:
application\language\english\bm_lang.php
application\language\zh-cn\bm_lang.php
Attention:
1. The prefix of "_lang.php" should be consistent;
2. If there are other language packs, you can create the file application\language\***\bm_lang.php (* * for your own name, to correspond to different languages)
The implementation code is as follows:
Public Function lang ($line, $param = Array ()) {//Judge browser language $default _lang_arr = $_server[' http_accept_language '];
$strarr = Explode (",", $default _lang_arr);
$default _lang = $strarr [0];
echo ' 1 '. $default _lang; Sets the language based on the browser type if ($default _lang = = ' en-US ' | | | $default _lang = = = $this->config->set_item (' language ', ' Englis
h ');
Load the language pack according to the set language type $this->load->language (' BM ', ' 中文版 ');
}else{$this->config->set_item (' language ', ' ZH-CN ');
$this->load->language (' BM ', ' ZH-CN ');
}//Current language//echo ' 2 '. $this->config->item (' language ');
According to the translation of a language tag in a language pack, whether the language pack is used $line = ' title ';
$param = Array ();
$CI = & Get_instance ();
$line = $CI->lang->line ($line);
The above two lines are equivalent to the following line,& get_instance () instantiated $line = $this->lang->line (' title ');
if (Is_array ($param) && count ($param) > 0) {array_unshift ($param, $line);
$line = Call_user_func_array (' sprintf ', $param);
Echo ' ^_^ '. $line; }