Skip to content

Commit 6a71601

Browse files
committed
🧭 fix(docs): show API index in EN/JA by aligning api meta.json with ZH
- Mark `content/docs/en/api` and `content/docs/ja/api` as root folders (`root: true`) - Add consistent page ordering to include `index`, `ai-model`, and `management` - Fill in localized title/description/icon so the API section appears in the sidebar tabs
1 parent de6e1e2 commit 6a71601

File tree

9 files changed

+83
-16
lines changed

9 files changed

+83
-16
lines changed

content/docs/en/api/meta.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
{
2-
"title": "API"
2+
"title": "API Reference",
3+
"description": "New API Complete API Documentation",
4+
"icon": "Code",
5+
"root": true,
6+
"pages": ["index", "ai-model", "management"]
37
}

content/docs/en/guide/wiki/changelog.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Changelog
44

55
import { Callout } from 'fumadocs-ui/components/callout';
66

7-
<Callout type="warn" title="Version Log Information · Data updated at 2026-1-4 23:18:11">
7+
<Callout type="warn" title="Version Log Information · Data updated at 2026-1-5 00:07:28">
88
To view all historical versions, please visit the [GitHub Releases page](https://github.com/QuantumNous/new-api/releases). This page automatically fetches the latest update information from that page.
99
</Callout>
1010

content/docs/en/guide/wiki/special-thanks.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The development of New API would not be possible without the support and contrib
1010

1111
Below is a list of all developers who have contributed to the project. We thank them for their hard work and creativity!
1212

13-
<Callout title="Contributor Information · Data updated at 2026-1-4 23:18:11 (UTC+8)">
13+
<Callout title="Contributor Information · Data updated at 2026-1-5 00:07:28 (UTC+8)">
1414
The following contributor data is automatically retrieved from the [GitHub Contributors page](https://github.com/QuantumNous/new-api/graphs/contributors) for the top 50 contributors. The top three contributors are marked with gold, silver, and bronze borders respectively. If you would also like to contribute to the project, you are welcome to submit a Pull Request.
1515
</Callout>
1616

content/docs/ja/api/meta.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
{
2-
"title": "API"
2+
"title": "APIリファレンス",
3+
"description": "New API の完全なインターフェースドキュメント",
4+
"icon": "Code",
5+
"root": true,
6+
"pages": ["index", "ai-model", "management"]
37
}

content/docs/ja/guide/wiki/changelog.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: 変更履歴
44

55
import { Callout } from 'fumadocs-ui/components/callout';
66

7-
<Callout type="warn" title="バージョンログ情報 · データ更新日時 2026-1-4 23:18:11">
7+
<Callout type="warn" title="バージョンログ情報 · データ更新日時 2026-1-5 00:07:28">
88
すべての履歴バージョンを表示するには、[GitHub Releases ページ](https://github.com/QuantumNous/new-api/releases)をご覧ください。このページは定期的に最新の更新情報を取得します。
99
</Callout>
1010

content/docs/ja/guide/wiki/special-thanks.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ New API の開発は、コミュニティのサポートと貢献なしには実
1010

1111
以下は、プロジェクトに貢献してくださったすべての開発者のリストです。彼らの勤勉な作業と創造性に感謝します!
1212

13-
<Callout title="貢献者情報 · データ更新日時 2026-1-4 23:18:11 (UTC+8)">
13+
<Callout title="貢献者情報 · データ更新日時 2026-1-5 00:07:28 (UTC+8)">
1414
以下の貢献者データは、[GitHub Contributors ページ](https://github.com/QuantumNous/new-api/graphs/contributors)から上位50名を自動的に取得します。貢献度上位3名は、それぞれゴールド、シルバー、ブロンズの枠で識別されます。プロジェクトに貢献したい場合は、プルリクエストを送信してください。
1515
</Callout>
1616

content/docs/zh/guide/wiki/changelog.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: 更新日志
44

55
import { Callout } from 'fumadocs-ui/components/callout';
66

7-
<Callout type="warn" title="版本日志信息 · 数据更新于 2026-1-4 23:18:11">
7+
<Callout type="warn" title="版本日志信息 · 数据更新于 2026-1-5 00:07:28">
88
如需查看全部历史版本,请访问 [GitHub Releases 页面](https://github.com/QuantumNous/new-api/releases),本页面从该页面定时获取最新更新信息。
99
</Callout>
1010

content/docs/zh/guide/wiki/special-thanks.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ New API 的开发离不开社区的支持和贡献。在此特别感谢所有为
1010

1111
以下是所有为项目做出贡献的开发者列表。在此感谢他们的辛勤工作和创意!
1212

13-
<Callout title="贡献者信息 · 数据更新于 2026-1-4 23:18:11 (UTC+8)">
13+
<Callout title="贡献者信息 · 数据更新于 2026-1-5 00:07:27 (UTC+8)">
1414
以下贡献者数据从 [GitHub Contributors 页面](https://github.com/QuantumNous/new-api/graphs/contributors) 自动获取前50名。贡献度前三名分别以金、银、铜牌边框标识。如果您也想为项目做出贡献,欢迎提交 Pull Request。
1515
</Callout>
1616

scripts/translate-docs.ts

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,14 @@ interface TranslationResult {
6969
}
7070

7171
// ============================================================================
72-
// Validation
72+
// Validation (deferred)
7373
// ============================================================================
74-
75-
if (!OPENAI_API_KEY) {
76-
console.error('❌ Error: OPENAI_API_KEY environment variable is not set');
77-
process.exit(1);
74+
// NOTE: Do not exit at import time. This file is also imported by tooling/scripts.
75+
function assertOpenAIKey() {
76+
if (!OPENAI_API_KEY) {
77+
console.error('❌ Error: OPENAI_API_KEY environment variable is not set');
78+
process.exit(1);
79+
}
7880
}
7981

8082
// ============================================================================
@@ -90,7 +92,57 @@ const BASE_TRANSLATION_RULES = `
9092
5. 图片路径、链接路径保持不变(如果路径中包含中文目录,保持原样)
9193
6. Front matter (YAML 头部) 中的内容需要翻译
9294
7. 保持原文的语气和风格
93-
8. 对于特殊的专有名词(如产品名 "New API"、"Cherry Studio" 等),保持不变`;
95+
8. 对于特殊的专有名词(如产品名 "New API"、"Cherry Studio" 等),保持不变
96+
9. 如果文本中出现占位符(例如 @@FD_PROTECT_0@@),必须原样保留,不得翻译、改写、换行或添加空格`;
97+
98+
// ============================================================================
99+
// MDX Protection (Prevent AI from translating API/OpenAPI paths)
100+
// ============================================================================
101+
102+
const PROTECT_PREFIX = '@@FD_PROTECT_';
103+
const PROTECT_SUFFIX = '@@';
104+
105+
function protectMdxSegments(input: string): {
106+
protectedText: string;
107+
restore: (translated: string) => string;
108+
tokens: string[];
109+
} {
110+
const replacements: Array<{ token: string; value: string }> = [];
111+
let protectedText = input;
112+
113+
function protectByRegex(re: RegExp) {
114+
protectedText = protectedText.replace(re, (match) => {
115+
const token = `${PROTECT_PREFIX}${replacements.length}${PROTECT_SUFFIX}`;
116+
replacements.push({ token, value: match });
117+
return token;
118+
});
119+
}
120+
121+
// Protect the entire <APIPage ... /> component (it often contains OpenAPI JSON paths).
122+
protectByRegex(/<APIPage\b[\s\S]*?\/>/g);
123+
124+
// Extra safety: protect any remaining OpenAPI generated JSON path outside APIPage.
125+
protectByRegex(/openapi\/generated\/[^\s"'<>)}\]]+?\.json/g);
126+
127+
const tokens = replacements.map((r) => r.token);
128+
const restore = (translated: string) => {
129+
// Ensure model didn't drop/alter tokens. If it did, retry to avoid corrupting paths.
130+
for (const t of tokens) {
131+
if (!translated.includes(t)) {
132+
throw new Error(
133+
`Translation output is missing protected token: ${t}. Refusing to write corrupted content.`
134+
);
135+
}
136+
}
137+
let out = translated;
138+
for (const r of replacements) {
139+
out = out.split(r.token).join(r.value);
140+
}
141+
return out;
142+
};
143+
144+
return { protectedText, restore, tokens };
145+
}
94146

95147
function getPlainTextTranslationPrompt(
96148
targetLang: LanguageCode,
@@ -187,8 +239,12 @@ async function translateContent(
187239
);
188240
}
189241

190-
const prompt = getTranslationPrompt(targetLang, content);
191-
return await callOpenAI(prompt, targetLang);
242+
// Protect critical MDX segments (e.g. <APIPage document={...} />) so AI won't translate paths.
243+
const { protectedText, restore } = protectMdxSegments(content);
244+
245+
const prompt = getTranslationPrompt(targetLang, protectedText);
246+
const translated = await callOpenAI(prompt, targetLang);
247+
return restore(translated);
192248
} catch (error) {
193249
lastError = error as Error;
194250
retryCount++;
@@ -601,6 +657,7 @@ async function processFiles(
601657
// ============================================================================
602658

603659
async function translateDocs(specificPaths?: string[]) {
660+
assertOpenAIKey();
604661
console.log('═══════════════════════════════════════════════');
605662
console.log('🌐 Starting document translation...');
606663
console.log('═══════════════════════════════════════════════\n');
@@ -711,3 +768,5 @@ if (require.main === module) {
711768
}
712769

713770
export { translateDocs };
771+
// Export for testing/tooling (e.g. to verify OpenAPI path protection).
772+
export { protectMdxSegments };

0 commit comments

Comments
 (0)