This article mainly introduces CodeIgniter's use of multiple languages controlled by config to realize automatic Conversion Based on browser language, which is very practical, for more information about CodeIgniter, see the example below. CodeIgniter uses multiple languages controlled by config to implement automatic Conversion Based on browser languages, which is very practical for website development.
The procedure is as follows:
The language package file is as follows:
application\language\english\bm_lang.phpapplication\language\zh-cn\bm_lang.php
Note:
1. the prefix of "_ lang. php" must be consistent;
2. If there are other language packs, you can create the file application \ language \ *** \ bm_lang.php (*** for your own name, corresponding to different languages)
The implementation code is as follows:
Public function lang ($ line, $ param = array () {// judge the browser language $ default_lang_arr = $ _ SERVER ['HTTP _ ACCEPT_LANGUAGE ']; $ strarr = explode (",", $ default_lang_arr); $ default_lang = $ strarr [0]; // echo '1 '. $ default_lang; // set the language if ($ default_lang = 'en-us' | $ default_lang = 'en') based on the browser type ') {$ this-> config-> set_item ('language ', 'English '); // load the language Pack according to the language type you set $ this-> load-> language ('bm ', 'English ');} else {$ this-> config-> set_item ('language ', 'zh-cn'); $ this-> load-> language ('bm ', 'zh-cn');} // current language // echo '2 '. $ this-> config-> item ('language'); // determines whether the language Pack $ line = 'title' is used based on the translation of a language mark in the language Pack '; $ param = array (); // $ CI = & get_instance (); // $ line = $ CI-> lang-> line ($ line ); // The above two rows are equivalent to the following row. & get_instance () is 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 'prop _^ '. $ line ;}