保存一种语言的译文
curl --request PUT \
--url https://api-datahub.bazhuayu.com/v1/data-apps/{app_id}/translations/{locale} \
--header 'Content-Type: application/json' \
--data '
{
"entries": {},
"expected_revision": 123
}
'import requests
url = "https://api-datahub.bazhuayu.com/v1/data-apps/{app_id}/translations/{locale}"
payload = {
"entries": {},
"expected_revision": 123
}
headers = {"Content-Type": "application/json"}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({entries: {}, expected_revision: 123})
};
fetch('https://api-datahub.bazhuayu.com/v1/data-apps/{app_id}/translations/{locale}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));const options = {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({entries: {}, expected_revision: 123})
};
fetch('https://api-datahub.bazhuayu.com/v1/data-apps/{app_id}/translations/{locale}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api-datahub.bazhuayu.com/v1/data-apps/{app_id}/translations/{locale}"
payload := strings.NewReader("{\n \"entries\": {},\n \"expected_revision\": 123\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api-datahub.bazhuayu.com/v1/data-apps/{app_id}/translations/{locale}")
.header("Content-Type", "application/json")
.body("{\n \"entries\": {},\n \"expected_revision\": 123\n}")
.asString();<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-datahub.bazhuayu.com/v1/data-apps/{app_id}/translations/{locale}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'entries' => [
],
'expected_revision' => 123
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}require 'uri'
require 'net/http'
url = URI("https://api-datahub.bazhuayu.com/v1/data-apps/{app_id}/translations/{locale}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"entries\": {},\n \"expected_revision\": 123\n}"
response = http.request(request)
puts response.read_bodyusing RestSharp;
var options = new RestClientOptions("https://api-datahub.bazhuayu.com/v1/data-apps/{app_id}/translations/{locale}");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddJsonBody("{\n \"entries\": {},\n \"expected_revision\": 123\n}", false);
var response = await client.PutAsync(request);
Console.WriteLine("{0}", response.Content);
val client = OkHttpClient()
val mediaType = MediaType.parse("application/json")
val body = RequestBody.create(mediaType, "{\n \"entries\": {},\n \"expected_revision\": 123\n}")
val request = Request.Builder()
.url("https://api-datahub.bazhuayu.com/v1/data-apps/{app_id}/translations/{locale}")
.put(body)
.addHeader("Content-Type", "application/json")
.build()
val response = client.newCall(request).execute()false{
"locale": "<string>",
"origin": {},
"revision": 123,
"based_on_version": "<string>",
"based_on_hash": "<string>",
"stale": true,
"stale_paths": [
"<string>"
],
"warnings": [
{
"code": "<string>",
"params": {}
}
]
}发布与运营
保存一种语言的译文
整份替换某种语言的译文 overlay;不产生新版本,对所有版本生效。
PUT
/
v1
/
data-apps
/
{app_id}
/
translations
/
{locale}
保存一种语言的译文
curl --request PUT \
--url https://api-datahub.bazhuayu.com/v1/data-apps/{app_id}/translations/{locale} \
--header 'Content-Type: application/json' \
--data '
{
"entries": {},
"expected_revision": 123
}
'import requests
url = "https://api-datahub.bazhuayu.com/v1/data-apps/{app_id}/translations/{locale}"
payload = {
"entries": {},
"expected_revision": 123
}
headers = {"Content-Type": "application/json"}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({entries: {}, expected_revision: 123})
};
fetch('https://api-datahub.bazhuayu.com/v1/data-apps/{app_id}/translations/{locale}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));const options = {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({entries: {}, expected_revision: 123})
};
fetch('https://api-datahub.bazhuayu.com/v1/data-apps/{app_id}/translations/{locale}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api-datahub.bazhuayu.com/v1/data-apps/{app_id}/translations/{locale}"
payload := strings.NewReader("{\n \"entries\": {},\n \"expected_revision\": 123\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api-datahub.bazhuayu.com/v1/data-apps/{app_id}/translations/{locale}")
.header("Content-Type", "application/json")
.body("{\n \"entries\": {},\n \"expected_revision\": 123\n}")
.asString();<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-datahub.bazhuayu.com/v1/data-apps/{app_id}/translations/{locale}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'entries' => [
],
'expected_revision' => 123
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}require 'uri'
require 'net/http'
url = URI("https://api-datahub.bazhuayu.com/v1/data-apps/{app_id}/translations/{locale}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"entries\": {},\n \"expected_revision\": 123\n}"
response = http.request(request)
puts response.read_bodyusing RestSharp;
var options = new RestClientOptions("https://api-datahub.bazhuayu.com/v1/data-apps/{app_id}/translations/{locale}");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddJsonBody("{\n \"entries\": {},\n \"expected_revision\": 123\n}", false);
var response = await client.PutAsync(request);
Console.WriteLine("{0}", response.Content);
val client = OkHttpClient()
val mediaType = MediaType.parse("application/json")
val body = RequestBody.create(mediaType, "{\n \"entries\": {},\n \"expected_revision\": 123\n}")
val request = Request.Builder()
.url("https://api-datahub.bazhuayu.com/v1/data-apps/{app_id}/translations/{locale}")
.put(body)
.addHeader("Content-Type", "application/json")
.build()
val response = client.newCall(request).execute()false{
"locale": "<string>",
"origin": {},
"revision": 123,
"based_on_version": "<string>",
"based_on_hash": "<string>",
"stale": true,
"stale_paths": [
"<string>"
],
"warnings": [
{
"code": "<string>",
"params": {}
}
]
}端点
PUT https://api-datahub.bazhuayu.com/v1/data-apps/{app_id}/translations/{locale}
404。
整份替换某种语言的 overlay,来源记为 author。保存译文不会产生 Release:译文挂在 App 身份上,对所有版本生效。
硬检查(400):语言代码合法且不等于 App 的 source_locale;条目必须把路径映射到字符串或字符串数组;单个 App 最多 20 种语言;超过 4MB 为 413。路径级问题(未知路径、类型不符、enum_titles 长度与 enum 不匹配、事件或示例 id 重复)作为 warnings 返回而不拒绝,消费侧跳过这些条目。
哈希基准是工作区(作者翻译时看到的内容),没有草稿时回落到最新 Release;响应里的 stale 按最新 Release 计算,所以为尚未发布的草稿改动保存的译文会报 stale=true,直到那次改动发布。expected_revision 不一致为 409。
请求
路径参数
string
必填
App 引用。
string
必填
语言代码。
请求体
object
必填
译文条目,键为 manifest 路径,值为字符串或字符串数组。
integer
期望的当前草稿版本号。
示例请求
curl -X PUT \
-H "Authorization: Bearer $BAZHUAYU_API_KEY" \
-H "Content-Type: application/json" \
-d '{"entries": {"identity.name": "Product Review Lookup", "identity.summary": "Fetch public reviews by product id"}, "readme": "# Product Review Lookup\n…"}' \
"https://api-datahub.bazhuayu.com/v1/data-apps/carol/reviews-query/translations/en"
响应
200 成功
{
"data": {
"locale": "string",
"origin": "author",
"revision": 0,
"based_on_version": "string",
"based_on_hash": "string",
"stale": false,
"stale_paths": [
"string"
],
"warnings": [
{
"code": "string",
"params": {}
}
]
}
}
data 字段中,其内容如下。
string
必填
语言代码。
enum
必填
译文来源。 取值:
author / platform。integer
必填
—
string
—
string
必填
—
boolean
必填
原文是否已在译文之后变化。
string[]
发生变化的路径。
错误
| HTTP | code | category | 说明 |
|---|---|---|---|
| 401 | unauthorized | forbidden | 缺少或无效的 API Key。 |
| 400 | locale-invalid | invalid_input | 语言代码不合法。 |
| 400 | locale-is-source | invalid_input | 目标语言与 App 的源语言相同。 |
| 400 | translation-invalid | invalid_input | 译文条目形状不合法(路径必须映射到字符串或字符串数组)。 |
| 400 | translation-locale-limit | invalid_input | 单个 App 最多 20 个语言。 |
| 413 | payload-too-large | invalid_input | 请求体超过大小限制。 |
| 409 | revision-conflict | invalid_input | expected_revision 与当前草稿版本号不一致,说明有并发修改。 |
{"error": {code, category, message, retryable}},见错误。
