API Translation User Manual
illustrate:
use
Db::return_json_exit()
When using the method, you can specify the path of the field to be translated through the second parameter.
Basic usage
1. Translate specific fields
Translate all Chinese text under `pricing_plans` and the value of `message`:
Db::return_json_exit([
'code' => 200,
'message' => '成功',
'data' => [
'pricing_plans' => [
'basic' => [
'name' => '基础套餐',
'price' => 99,
'features' => ['功能一', '功能二']
],
'pro' => [
'name' => '专业套餐',
'price' => 299,
'features' => ['高级功能', '优先支持']
]
],
'user' => [
'name' => '张三',
'profile' => [
'city' => '北京',
'bio' => '个人简介'
]
],
'aaa' => '你好'
]
], ['data.pricing_plans.*', 'message']);
2. Translate specified paths and subpaths
Translate all Chinese characters below the specific fields name and pro:
Db::return_json_exit([
'code' => 200,
'message' => '成功',
'data' => [
'pricing_plans' => [
'basic' => [
'name' => '基础套餐',
'price' => 99,
'features' => ['功能一', '功能二']
],
'pro' => [
'name' => '专业套餐',
'price' => 299,
'features' => ['高级功能', '优先支持']
]
],
'user' => [
'name' => '张三',
'profile' => [
'city' => '北京',
'bio' => '个人简介'
]
],
'aaa' => '你好'
]
], ['data.pricing_plans.basic.name', 'data.pricing_plans.pro.*']);
3. Translate the entire data object
Translate all content under the data folder using wildcards:
Db::return_json_exit([
'code' => 200,
'message' => '成功',
'data' => [
'pricing_plans' => [
'basic' => [
'name' => '基础套餐',
'price' => 99,
'features' => ['功能一', '功能二']
],
'pro' => [
'name' => '专业套餐',
'price' => 299,
'features' => ['高级功能', '优先支持']
]
],
'user' => [
'name' => '张三',
'profile' => [
'city' => '北京',
'bio' => '个人简介'
]
],
'aaa' => '你好'
]
], ['data.*']);
4. Do not translate (default)
The second parameter is omitted, and no translation is performed:
Db::return_json_exit([
'code' => 200,
'message' => '成功',
'data' => [
'pricing_plans' => [
'basic' => [
'name' => '基础套餐',
'price' => 99,
'features' => ['功能一', '功能二']
],
'pro' => [
'name' => '专业套餐',
'price' => 299,
'features' => ['高级功能', '优先支持']
]
],
'user' => [
'name' => '张三',
'profile' => [
'city' => '北京',
'bio' => '个人简介'
]
],
'aaa' => '你好'
]
]);
Path syntax description
field- Translate top-level fieldsdata.field- Translate nested fieldsdata.*- All fields under the translation objectdata.array.*- Translate all contents under array/object