Legitmark 支持分类数据的本地化 API 响应 — 类别、类型、面、服务、阶段和原因。当您设置 Accept-Language 标头时,可翻译的字段将以请求的语言而非英语返回。
这对于以用户首选语言显示类别名称、拍照说明和拒绝原因非常有用。
支持的语言
| 语言代码 | 语言 | 示例 Accept-Language |
|---|
en | 英语(默认) | Accept-Language: en |
zh | 简体中文 | Accept-Language: zh |
ja | 日语 | Accept-Language: ja |
如果省略标头或包含不支持的语言,API 默认返回英语。
使用方法
在返回可翻译数据的任何请求中添加 Accept-Language 标头:
const response = await fetch('https://api.legitmark.com/api/v2/categories?active_only=true', {
headers: {
'Authorization': 'Bearer leo_xxxxxxxxx',
'Accept-Language': 'zh'
}
});
const { data } = await response.json();
// data[0].name → "箱包"(而不是 "Bags")
响应包含 Content-Language 标头确认使用的语言:
可翻译的端点
以下端点支持本地化响应:
| 端点 | 翻译字段 |
|---|
GET /api/v2/categories | name |
GET /api/v2/categories/:uuid | name |
GET /api/v2/categories/:uuid/types | name(类型) |
GET /api/v2/categories/tree | name(类别和类型) |
| 端点 | 翻译字段 |
|---|
GET /api/v2/types | name |
GET /api/v2/types/:uuid | name |
面(拍照要求)
| 端点 | 翻译字段 |
|---|
GET /api/v2/sides | name、description |
GET /api/v2/sides/:uuid | name、description |
GET /api/v2/sr/:uuid/side-groups | name、description(嵌套面) |
面的翻译对于向用户显示拍照说明特别有用。例如,“正面”及其描述“拍摄物品正面的清晰照片”可以以用户的语言显示。
原因(拒绝原因)
| 端点 | 翻译字段 |
|---|
GET /api/v2/reasons | name、description |
GET /api/v2/reasons/:uuid | name、description |
GET /api/v2/reasons/grouped | name、description |
| 端点 | 翻译字段 |
|---|
GET /api/services/:uuid | name、description |
| 端点 | 翻译字段 |
|---|
| 阶段端点 | title、description |
服务请求(V2)
| 端点 | 翻译字段 |
|---|
GET /api/v2/sr/:uuid | 嵌入的类别、类型、面和原因均已翻译 |
示例:本地化分类体系流程
典型的集成以用户的语言呈现分类体系选择:
const userLocale = 'zh'; // 来自用户偏好
const headers = {
'Authorization': 'Bearer leo_xxxxxxxxx',
'Accept-Language': userLocale
};
// 第 1 步:获取中文类别
const categoriesRes = await fetch(
'https://api.legitmark.com/api/v2/categories?active_only=true',
{ headers }
);
const { data: categories } = await categoriesRes.json();
// → [{name: "箱包", uuid: "..."}, {name: "手表", uuid: "..."}, ...]
// 第 2 步:获取选定类别的类型(也是中文)
const typesRes = await fetch(
`https://api.legitmark.com/api/v2/categories/${selectedCategoryUuid}/types`,
{ headers }
);
const { data: types } = await typesRes.json();
// → [{name: "托特包", uuid: "..."}, ...]
// 第 3 步:创建 SR 后,获取本地化说明的面组
const sidesRes = await fetch(
`https://api.legitmark.com/api/v2/sr/${srUuid}/side-groups`,
{ headers }
);
const { data: sideGroups } = await sidesRes.json();
// 面具有翻译的名称和描述用于拍照指导
回退行为
- 如果特定字段的翻译不可用,则返回英文值
- 如果语言标头格式错误或不受支持,则使用英语
- 品牌和型号不会被翻译 — 它们在全球范围内使用原始名称
后续步骤
- 查看 分类体系 了解分类系统
- 实施 工作流程 完整的服务请求生命周期
- 设置 Webhooks 实时状态更新