In this paper, we use the example to describe the multi-language implementation of CodeIgniter using Config control, which is very useful for website development according to the browser language automatic conversion function.
Here's how it works:
The language pack files are as follows:
application\language\english\bm_lang.phpapplication\language\zh-cn\bm_lang.php
Attention:
1. The prefix of "_lang.php" should be consistent;
2. If you have additional language packs, you can create a 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 ()) {//Judging browser language $default _lang_arr = $_ server[' Http_accept_language ']; $strarr = Explode (",", $default _lang_arr); $default _lang = $strarr [0]; echo ' 1 '. $default _lang; Set language if according to browser type ($default _lang = = ' en-US ' | | $default _lang = = ' en ') {$this->config->set_item (' language ', ' 中文版 '); Load the language pack according to the language type set $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 '); Determines whether a language pack is used $line = ' title ', based on the translation of a language tag in the language pack; $param = Array (); $CI = & Get_instance (); $line = $CI->lang->line ($line); The above two lines are equivalent to the following line of,& get_instance () instantiation $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;}