Skip to content

Commit 44fda8e

Browse files
committed
additional docs for korean
1 parent 53a8025 commit 44fda8e

File tree

2 files changed

+68
-115
lines changed

2 files changed

+68
-115
lines changed

docs/scripts/translate_docs.py

Lines changed: 5 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@
3636
# Add more languages here, e.g., "fr": "French"
3737
}
3838

39-
# Comma-separated list to restrict which languages to translate (e.g., "ko" or "ja,ko")
40-
ONLY_LANGS = [
41-
s.strip()
42-
for s in (os.environ.get("ONLY_LANG") or os.environ.get("LANGS") or "").split(",")
43-
if s.strip()
44-
]
45-
4639
# Initialize OpenAI client
4740
api_key = os.getenv("PROD_OPENAI_API_KEY") or os.getenv("OPENAI_API_KEY")
4841
openai_client = OpenAI(api_key=api_key)
@@ -90,7 +83,7 @@
9083
"file search": "ファイル検索",
9184
"streaming": "ストリーミング",
9285
"system prompt": "システムプロンプト",
93-
"Python-first": "Python ファースト",
86+
"Python first": "Python ファースト",
9487
# Add more Japanese mappings here
9588
},
9689
"ko": {
@@ -153,71 +146,7 @@
153146
}
154147

155148

156-
def _extract_sidebar_translations(lang_code: str) -> Dict[str, Dict[str, Optional[str]]]:
157-
"""Extract mapping of doc file paths to labels/translations from mkdocs.yml.
158-
159-
Returns a map: { path: { "label": str, "translation": str|None } }
160-
"""
161-
sidebar_map: Dict[str, Dict[str, Optional[str]]] = {}
162-
repo_root = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
163-
mkdocs_path = os.path.join(repo_root, "mkdocs.yml")
164-
if yaml is None:
165-
return sidebar_map
166-
try:
167-
with open(mkdocs_path, "r", encoding="utf-8") as f:
168-
data = yaml.safe_load(f)
169-
except Exception:
170-
return sidebar_map
171-
172-
try:
173-
languages_block = []
174-
for plugin in data.get("plugins", []):
175-
if isinstance(plugin, dict) and "i18n" in plugin:
176-
languages_block = plugin["i18n"].get("languages", [])
177-
break
178-
if not languages_block:
179-
return sidebar_map
180-
181-
nav_by_locale: Dict[str, Any] = {}
182-
for lang in languages_block:
183-
locale = lang.get("locale")
184-
nav_by_locale[locale] = lang.get("nav")
185-
186-
en_nav = nav_by_locale.get("en")
187-
tgt_nav = nav_by_locale.get(lang_code)
188-
189-
def collect(nav: Any) -> Dict[str, str]:
190-
result: Dict[str, str] = {}
191-
if not isinstance(nav, list):
192-
return result
193-
for item in nav:
194-
if isinstance(item, dict):
195-
for label, value in item.items():
196-
if isinstance(value, str):
197-
result[value] = str(label)
198-
else:
199-
result.update(collect(value))
200-
elif isinstance(item, str):
201-
continue
202-
return result
203-
204-
en_map = collect(en_nav) if en_nav else {}
205-
tgt_map = collect(tgt_nav) if tgt_nav else {}
206-
for path_key, en_label in en_map.items():
207-
sidebar_map[path_key] = {
208-
"label": en_label,
209-
"translation": tgt_map.get(path_key),
210-
}
211-
except Exception:
212-
return {}
213-
return sidebar_map
214-
215-
216-
def built_instructions(
217-
target_language: str,
218-
lang_code: str,
219-
sidebar_map: Optional[Dict[str, Dict[str, Optional[str]]]] = None,
220-
) -> str:
149+
def built_instructions(target_language: str, lang_code: str) -> str:
221150
do_not_translate_terms = "\n".join(do_not_translate)
222151
specific_terms = "\n".join(
223152
[f"* {k} -> {v}" for k, v in eng_to_non_eng_mapping.get(lang_code, {}).items()]
@@ -226,23 +155,6 @@ def built_instructions(
226155
eng_to_non_eng_instructions.get("common", [])
227156
+ eng_to_non_eng_instructions.get(lang_code, [])
228157
)
229-
sidebar_labels_block = ""
230-
if sidebar_map:
231-
label_lines: List[str] = []
232-
for link, entry in sidebar_map.items():
233-
if entry.get("translation"):
234-
label_lines.append(
235-
f"- {link}: {entry['translation']} (sidebar translation)"
236-
)
237-
elif entry.get("label"):
238-
label_lines.append(f"- {link}: {entry['label']} (sidebar label)")
239-
if label_lines:
240-
sidebar_labels_block = (
241-
"\n\n#########################\n## PAGE TITLES ##\n#########################\n"
242-
"When you see links to another page, consistently use the following labels:\n"
243-
+ "\n".join(label_lines)
244-
+ "\n\nAlways use these canonical translations for page titles and references."
245-
)
246158
return f"""You are an expert technical translator.
247159
248160
Your task: translate the markdown passed as a user input from English into {target_language}.
@@ -270,8 +182,6 @@ def built_instructions(
270182
- Inline code surrounded by single back‑ticks ( `like_this` ).
271183
- Fenced code blocks delimited by ``` or ~~~, including all comments inside them.
272184
- Link URLs inside `[label](URL)` – translate the label, never the URL.
273-
- When translating Markdown tables, preserve the exact table structure, including all delimiters (|), header separators (---), and row/column counts. Only translate the cell contents. Do not add, remove, or reorder columns or rows.
274-
{sidebar_labels_block}
275185
276186
#########################
277187
## HARD CONSTRAINTS ##
@@ -362,15 +272,6 @@ def translate_file(file_path: str, target_path: str, lang_code: str) -> None:
362272
code_blocks: list[str] = []
363273
code_block_chunks: list[str] = []
364274
for line in lines:
365-
# Treat single-line import statements as code blocks to avoid accidental translation
366-
if (
367-
ENABLE_CODE_SNIPPET_EXCLUSION is True
368-
and (in_code_block is False)
369-
and line.startswith("import ")
370-
):
371-
code_blocks.append(line)
372-
current_chunk.append(f"CODE_BLOCK_{(len(code_blocks) - 1):02}")
373-
continue
374275
if (
375276
ENABLE_SMALL_CHUNK_TRANSLATION is True
376277
and len(current_chunk) >= 120 # required for gpt-4.5
@@ -397,11 +298,7 @@ def translate_file(file_path: str, target_path: str, lang_code: str) -> None:
397298
# Translate each chunk separately and combine results
398299
translated_content: list[str] = []
399300
for chunk in chunks:
400-
instructions = built_instructions(
401-
languages[lang_code],
402-
lang_code,
403-
sidebar_map=_extract_sidebar_translations(lang_code),
404-
)
301+
instructions = built_instructions(languages[lang_code], lang_code)
405302
if OPENAI_MODEL.startswith("gpt-5"):
406303
response = openai_client.responses.create(
407304
model=OPENAI_MODEL,
@@ -440,18 +337,11 @@ def translate_file(file_path: str, target_path: str, lang_code: str) -> None:
440337

441338
def translate_single_source_file(file_path: str) -> None:
442339
relative_path = os.path.relpath(file_path, source_dir)
443-
if "ref/" in relative_path or not (
444-
file_path.endswith(".md") or file_path.endswith(".mdx")
445-
):
340+
if "ref/" in relative_path or not file_path.endswith(".md"):
446341
return
447342

448343
# Determine target languages
449-
target_langs = (
450-
[code for code in ONLY_LANGS if code in languages]
451-
if ONLY_LANGS
452-
else list(languages.keys())
453-
)
454-
for lang_code in target_langs:
344+
for lang_code in languages:
455345
target_dir = os.path.join(source_dir, lang_code)
456346
target_path = os.path.join(target_dir, relative_path)
457347

mkdocs.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,69 @@ plugins:
216216
- 실시간 에이전트:
217217
- realtime/quickstart.md
218218
- realtime/guide.md
219+
- API 레퍼런스:
220+
- 에이전트:
221+
- ref/index.md
222+
- ref/agent.md
223+
- ref/run.md
224+
- ref/memory.md
225+
- ref/repl.md
226+
- ref/tool.md
227+
- ref/tool_context.md
228+
- ref/result.md
229+
- ref/stream_events.md
230+
- ref/handoffs.md
231+
- ref/lifecycle.md
232+
- ref/items.md
233+
- ref/run_context.md
234+
- ref/tool_context.md
235+
- ref/usage.md
236+
- ref/exceptions.md
237+
- ref/guardrail.md
238+
- ref/model_settings.md
239+
- ref/agent_output.md
240+
- ref/function_schema.md
241+
- ref/models/interface.md
242+
- ref/models/openai_chatcompletions.md
243+
- ref/models/openai_responses.md
244+
- ref/mcp/server.md
245+
- ref/mcp/util.md
246+
- 트레이싱:
247+
- ref/tracing/index.md
248+
- ref/tracing/create.md
249+
- ref/tracing/traces.md
250+
- ref/tracing/spans.md
251+
- ref/tracing/processor_interface.md
252+
- ref/tracing/processors.md
253+
- ref/tracing/scope.md
254+
- ref/tracing/setup.md
255+
- ref/tracing/span_data.md
256+
- ref/tracing/util.md
257+
- 실시간:
258+
- ref/realtime/agent.md
259+
- ref/realtime/runner.md
260+
- ref/realtime/session.md
261+
- ref/realtime/events.md
262+
- ref/realtime/config.md
263+
- ref/realtime/model.md
264+
- 음성:
265+
- ref/voice/pipeline.md
266+
- ref/voice/workflow.md
267+
- ref/voice/input.md
268+
- ref/voice/result.md
269+
- ref/voice/pipeline_config.md
270+
- ref/voice/events.md
271+
- ref/voice/exceptions.md
272+
- ref/voice/model.md
273+
- ref/voice/utils.md
274+
- ref/voice/models/openai_provider.md
275+
- ref/voice/models/openai_stt.md
276+
- ref/voice/models/openai_tts.md
277+
- 확장:
278+
- ref/extensions/handoff_filters.md
279+
- ref/extensions/handoff_prompt.md
280+
- ref/extensions/litellm.md
281+
- ref/extensions/memory/sqlalchemy_session.md
219282

220283
extra:
221284
# Remove material generation message in footer

0 commit comments

Comments
 (0)