Internationalization is realized in Yii 2.0, and the translation part of the English description is the Chinese description (the English information returned by the WeChat interface)
1. When requesting the WeChat interface, the return code: 45028, the returned English information: Has No Massend Quota Rid: 6103DF2E-1505BA73-0EB14E1C. as shown in Figure 1
{
"errcode": 45028,
"errmsg": "has no masssend quota rid: 6103df2e-1505ba73-0eb14e1c"
}
2. The code is implemented as follows
$responseData = $wxServiceApi::wxMessageSendAll($requestData);
if (!isset($responseData['msg_id'])) {
$errcode = array_key_exists('errcode',$responseData)?$responseData['errcode']:205100;
throw new ServerErrorHttpException(Yii::t('error', Yii::t('error', Yii::t('error', '205100'), ['error_code' => $errcode, 'error_msg' => $responseData['errmsg']])), 205100);
}
3. The plan to convert the error message: Has No Masssend Quota Rid: 6103DF2E-1505BA73-0EB14E1C is translated as: no group quota. Rid: 6103DF2E-1505BA73-0EB14E1C. as shown in Figure 2
4. Add files common/messages/en-us/wx.php, common/messages/zh-cn/wx. php, wx/messages/en-us/wx.php, wx/messages/zh-cn/wx.php. as shown in Figure 3
common/messages/en-us/wx.php
common/messages/zh-cn/wx.php
'没有群发配额(订阅号为每天 1 次,服务号为每月 4 次)。',
'invalid content' => '无效内容(内容中包含音频)。',
];
wx/messages/en-us/wx.php
wx/messages/zh-cn/wx.php
5. The code is implemented as follows. where the code: substr($responseData[‘errmsg’], 0, $pos) The result is: has no masssend quota. where the code: substr($responseData[‘errmsg’], $pos) The result is: RID: 6103DF2E-1505BA73-0EB14E1C. Translate: has no massend quota as: no group quota. After that, splicing again: Rid: 6103DF2E-1505BA73-0EB14E1C.
$responseData = $wxServiceApi::wxMessageSendAll($requestData);
if (!isset($responseData['msg_id'])) {
$errcode = $responseData['errcode'] ?? 205100;
$pos = strpos($responseData['errmsg'], ' rid:');
$errorMsg = Yii::t('wx', substr($responseData['errmsg'], 0, $pos)) . substr($responseData['errmsg'], $pos);
throw new ServerErrorHttpException(Yii::t('error', Yii::t('error', Yii::t('error', '205100'), ['error_code' => $errcode, 'error_msg' => $errorMsg])), 205100);
}
6. For the returned English information: Invalid Content Hint:[pzRHda0286d228]Rid: 61041ffe-5cefd269-6c9611ff, the complete code is as follows. Messages at the source language do not support fuzzy matching.
$responseData = $wxServiceApi::wxMessageSendAll($requestData);
if (!isset($responseData['msg_id'])) {
$errcode = $responseData['errcode'] ?? 205100;
$errorMsg = '';
$pos = strpos($responseData['errmsg'], ' hint:');
if ($pos === false) {
$pos = strpos($responseData['errmsg'], ' rid:');
}
if ($pos !== false) {
$errorMsg = Yii::t('wx', substr($responseData['errmsg'], 0, $pos)) . substr($responseData['errmsg'], $pos);
}
throw new ServerErrorHttpException(Yii::t('error', Yii::t('error', Yii::t('error', '205100'), ['error_code' => $errcode, 'error_msg' => $errorMsg])), 205100);
}
7. Test translation results, Has No Masssend Quota Rid: 610A50C5-26966176-7CCEB46E has been translated as: No group quota (subscription number is 1 per day 1 time, the service number is 4 times a month). Rid: 610A50C5-26966176-7CCEB46E. in line with expectations. as shown in Figure 4
8. Test the translation results, invalid content hint:[dN7TKA0474d139]RID: 610A5A7A-5907E6C6-270B8278 has been translated as: Invalid content (with audio in the content). Hint:[dN7TKA0474d139]RID: 610A5A7A-5907E6C6-270B8278. in line with expectations. as shown in Figure 5
9. Since the Invalid Image Size has not been added to the language pack, Invalid Image Size hint:[cl_6Oa0457mp13]RID: 6103C6D0-481A4BED-73E7120A Keep it as it is. in line with expectations.
'没有群发配额(订阅号为每天 1 次,服务号为每月 4 次)。',
'invalid content' => '无效内容(内容中包含音频)。',
'invalid image size' => '图片尺寸太大(大小必须在10MB以下)。',
];
11. Test the translation results, invalid image size hint:[flp8Ba0298w689]Rid: 610a6969-72bb79c0-4b069755 has been translated as: invalid image size hint:[flp8Ba0298w689]Rid: 610a6969-72bb79c0-4b069755. The blue box is the English information before the translation, and the red box is the translated Chinese information. in line with expectations. as shown in Figure 6




![测试翻译结果,invalid content hint: [dN7TKA0474d139] rid: 610a5a7a-5907e6c6-270b8278 已经被翻译为:无效内容(内容中包含音频)。 hint: [dN7TKA0474d139] rid: 610a5a7a-5907e6c6-270b8278。符合预期](https://www.shuijingwanwq.com/wp-content/uploads/2021/08/5-2.png)
![测试翻译结果,invalid image size hint: [flp8Ba0298w689] rid: 610a6969-72bb79c0-4b069755 已经被翻译为:invalid image size hint: [flp8Ba0298w689] rid: 610a6969-72bb79c0-4b069755。蓝框中是翻译前的英文信息,红框中是翻译后的中文信息。符合预期](https://www.shuijingwanwq.com/wp-content/uploads/2021/08/6-1.png)