/* Website Language English Solution--by changing the buffer to achieve Function: According to the cookie to determine the user's choice of language, the default is Chinese (do not replace), when the user selects English in the page, then through the JS write the cookie language status code, this page through the judgment change the cookie to determine whether the language translation. Description: In the front end through the JS to determine the user's choice of language, the user chooses English, JS write the cookie language state as ' EN ', the background program by judging the cookie saved language encoding to perform language translation operations. Author: AIBHSC How to use: in the following file to replace the Chinese and English, and then in the program portal file reference the file. Application scenario: For the Enterprise website English is not used frequently, modify the program and the database is too expensive, but also must be in English website, you can try to use this program. */
- /*
- Web site language handlers--by changing the buffer to achieve
- Function: According to the cookie to determine the user's choice of language, the default is Chinese (do not replace), when the user selects English in the page, then through the JS write the cookie language status code, this page through the judgment change the cookie to determine whether the language translation.
- Description: In the front end through the JS to determine the user's choice of language, the user chooses English, JS write the cookie language state as ' EN ', the background program by judging the cookie saved language encoding to perform language translation operations.
- Author: AIBHSC
- How to use: in the following file to replace the Chinese and English, and then in the program portal file reference the file.
- Application scenario: For the Enterprise website English is not used frequently, modify the program and the database is too expensive, but also must be in English website, you can try to use this program.
- */
- Through one-dimensional array storage language pack, save space, convenient key processing, note: ① key value do not dislocation; ② long string precedence
- Language Pack, put the content to be translated here--start
- $CN []= ' user login '; $en []= ' userlogin ';
- $CN []= ' login '; $en []= ' login ';
- $CN []= ' registration '; $en []= ' Reg ';
- $CN []= ' home '; $en []= ' home ';
- $CN []= ' view '; $en []= ' View ';
- $CN []= ' whereabouts '; $en []= ' Local ';
- $CN []= ' drill weight '; $en []= ' Weight ';
- $CN []= ' state inspection '; $en []= ' NGTC ';
- $CN []= '; $en []= ';
- Language Pack--end
- A global definition that references a language pack.
- $GLOBALS [' GLOBAL_CN ']=& $cn;
- $GLOBALS [' global_en ']=& $en;
- $GLOBALS [' Global_lang ']=$_cookie[' User_lang ']?$_cookie[' User_lang ']: ' CN ';
- Cache ();//Perform language translation operations
- function cache () {
- Ob_start (Array ($this, "Autocache"))//Do not understand this line please see the PHP manual Call_user_func fourth Example "Example #4"
- }
- function Cn2en ($body) {//parameter: $body the content to be translated; $arr _cn Chinese Language pack; $arr _en English Language pack; return value: Replaced string
- When the two language pack key values are incorrect, the original value is returned without any action.
- if (count ($GLOBALS [' GLOBAL_CN ']) <>count ($GLOBALS [' global_en ']) {return $body;}
- When the user chooses English, the Chinese in the document is replaced by the language pack in English
- if ($GLOBALS [' Global_lang ']== ' EN ') {$body =str_ireplace ($GLOBALS [' GLOBAL_CN '], $GLOBALS [' global_en '], $body);}
- return $body;
- }
- function Autocache ($contents) {
- $contents = Cn2en ($contents);//Perform language translation
- return $contents;
- }
- ?>
Copy Code |