thinkphp PHP files are also external JS files common to the same language pack
One. PHP language Pack to JSON data format
1. New validation field for language pack application\common\lang\validate-cn.php
<?PHP//Validation Field language Pack Chinesereturn [ 'Validate'=[ 'name'= [ 'Empty'='user name cannot be empty', 'length'='User name length 6-20 characters' ], 'Email'= [ 'Empty'='The mailbox cannot be empty', 'format'='Incorrect mailbox format' ], 'Password'=[ 'Empty'='The password cannot be empty', 'format'='password length is 6-20 characters' ], ]];
2.ZH-CN Importing Language Pack validate-cn.php data
<?PHP/** * Global Language Pack * ZH-CN **/$lang= Include (App_path.'common/lang/validate-cn.php');; $data= [ 'Success'='Successful execution ^_^', 'Error'='execution Failure (┬_┬)', 'Confirm'=[ '1'='is a', '2'='No', ], 'Check'=[ '1'='has been audited', '2'='not audited', '3'='Disabled' ], 'Sex'=[ '1'='Confidentiality', '2'='male', '3'='female' ]];returnArray_merge ($lang, $data);
The purpose of this is to put the "common language pack" and "Field validation language pack" side in different files, and then merge the data. The JSON data is transferred to the Thinkphp method or to the initialized place.
Public function _initialize () { // instantiation of the validation language pack $lang = lang ('validate') ; = Json_encode ($lang); // go to JSON string $This->assign ('validate', $validate); }
And the variable is instantiated, the following HTML page will pass the instantiated variables of JS (recommended in the Global shared HTML page), add the following code
<script> // thinkphp Language Pack pass a JS var'{$validate}' ; </script>
Two. External JS receive PHP JSON language pack data Common.js
var lang=eval ('('+language+')') ; alert (lang.email.empty);
Output: Mailbox cannot be empty
thinkphp External JS Language pack