导出 INI
按导出模板(template_id)同步生成 INI 文件,上传到对象存储后返回 1 小时有效的下载签名 URL。
当前仅支持
type="project_strings"。task_strings因导出 filter 复杂(按 source/target 语言对过滤)暂不通过开放平台暴露 —— 后续版本会补上。
请求地址
POST {BASE_URL}/api/open/v1/export/ini鉴权 Header
和 创建翻译任务 完全一样。POST 的 raw body 参与签名:MD5(timestamp + raw_body + appSecret)。
请求体(JSON)
json
{
"type": "project_strings",
"template_id": "tpl-9d3f1a2c",
"target_languages": ["en", "ja"],
"download_mode": "single",
"escape_mode": "no-escape",
"filename": "v1.0_en_ja"
}字段说明
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
type | string | 是 | 当前仅支持 project_strings(项目字符串 / 全文本) |
template_id | string | 是 | 模板 ID。模板必须满足 format=ini(可在 创建模板 时设置) |
target_languages | string[] | 否 | 覆盖模板的 languages;为空则用模板自身的 languages,且模板的 languages 也为空时 422 |
download_mode | string | 否 | 覆盖模板的 mode:single(多语言一个 INI)/ separate(每语言一个 INI 打 ZIP)。默认沿用模板,模板未设则 single |
escape_mode | string | 否 | 覆盖项目设置 export_settings.ini_escape_mode:escape(转义 \n / \r / \t / \\)/ no-escape(原样输出)。默认沿用项目设置,项目未设则 no-escape |
filename | string | 否 | 导出文件名前缀(自动加 .ini 或 .ini.zip 扩展名);为空时用 {projectId}_{timestamp} |
响应
json
{
"success": true,
"code": 0,
"msg": "ok",
"trace_id": "...",
"data": {
"download_url": "https://storage.googleapis.com/loxily-export/...&Signature=...",
"expires_at": "2026-05-12T13:00:00.000Z",
"file_size": 12345,
"format": "ini",
"download_mode": "single",
"target_languages": ["en", "ja"],
"escape_mode": "no-escape"
}
}| 字段 | 类型 | 说明 |
|---|---|---|
download_url | string | GCS v4 签名 URL,浏览器/客户端可直接下载,有效期 1 小时 |
expires_at | string | 签名过期时间(ISO 8601) |
file_size | int | 文件大小(字节) |
format | string | 固定 ini |
download_mode | string | 实际生效的模式(single / separate) |
target_languages | string[] | 实际导出的语言 |
escape_mode | string | 实际生效的转义模式 |
行为说明
- 范围:固定
scope=all(项目下所有 string)。开放接口不支持页面端的"按当前过滤视图导出"。 - 空值过滤:每条记录里
target_lang为空 / null 的语言不会写进 INI;string_id为空的整行跳过。 - 数据量:典型项目 1k–10k 条 string,多语言 separate 模式打 ZIP 大约几十毫秒到几秒。接口超时 5 分钟,超大数据量请分多次(按语言子集)调用。
- 下载 URL:返回后请尽快下载(1 小时过期);如需再下载,重新调用本接口即可(每次返回新签名 URL)。
错误码
| code | 说明 |
|---|---|
| 400 | 请求体不是合法 JSON / template_id 缺失 / download_mode / escape_mode / target_languages / filename 类型或值非法 |
| 401 | 签名校验失败 / 时间戳过期 |
| 403 | App Secret 未配置 |
| 404 | template_id 对应的模板不存在 |
| 422 | type 不是 project_strings / 模板的 format 不是 ini / 合并模板后 languages 仍为空 |
| 500 | 导出执行失败 / GCS 上传失败 |
示例
bash
APP_KEY="5685414646a54423c891d87194d87f3f"
APP_SECRET="<你的 App Secret>"
BASE_URL="https://api.loxily.com"
BODY='{"type":"project_strings","template_id":"tpl-9d3f1a2c","target_languages":["en","ja"],"download_mode":"single"}'
TIMESTAMP=$(date +%s)
SIGN=$(printf '%s' "${TIMESTAMP}${BODY}${APP_SECRET}" | md5)
# 1) 调接口拿签名 URL
RESP=$(curl -s -X POST "${BASE_URL}/api/open/v1/export/ini" \
-H "Content-Type: application/json" \
-H "X-Loxily-AppKey: ${APP_KEY}" \
-H "X-Loxily-Timestamp: ${TIMESTAMP}" \
-H "X-Loxily-Sign: ${SIGN}" \
--data "${BODY}")
echo "$RESP"
# 2) 用 jq 提取 download_url 直接下载
URL=$(echo "$RESP" | jq -r '.data.download_url')
curl -L -o export.ini "$URL"