Skip to content

Commit 6a06847

Browse files
authored
번역 workflow 자동화 (#5)
* 번역 workflow 자동화 * 번역 workflow 자동화 * chore: add English translations for PR #3 * 번역 workflow 자동화 * 번역 workflow 자동화 * 번역 workflow 자동화 * 번역 workflow 자동화 * chore: add English translations for PR #5 * 번역 workflow 자동화
1 parent 0626afe commit 6a06847

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

scripts/translate_to_en.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import frontmatter
99
import yaml
10-
from slugify import slugify
1110

1211
try:
1312
from openai import OpenAI
@@ -28,6 +27,7 @@
2827
"- Do not hallucinate code or change code semantics.\n"
2928
"- Maintain YAML front matter formatting.\n"
3029
"- If there is mixed language, prefer English.\n"
30+
"- Do NOT change the file name or slug. The output will be saved using the exact same filename as the source (e.g., 2025-07-03-actions-runner-controller.md).\n"
3131
)
3232

3333

@@ -53,23 +53,15 @@ def load_korean_posts(only_paths: list[Path] | None = None) -> list[Path]:
5353
return sorted(POSTS_DIR.glob("*.md"))
5454

5555

56-
def to_en_filename(source_path: Path, en_title: str) -> Path:
57-
# source: YYYY-MM-DD-title.md -> keep date, replace slug with English slug
58-
date_prefix = source_path.name.split("-", 3)[:3]
59-
# Build english slug from translated title
60-
en_slug = slugify(en_title)
61-
filename = f"{date_prefix[0]}-{date_prefix[1]}-{date_prefix[2]}-{en_slug}.md"
62-
return POSTS_EN_DIR / filename
56+
def to_en_filename(source_path: Path) -> Path:
57+
# Keep the exact same filename as the source for the English post
58+
# Example: 2025-07-03-actions-runner-controller.md -> same name under _posts_en
59+
return POSTS_EN_DIR / source_path.name
6360

6461

6562
def needs_translation(src_file: Path) -> bool:
66-
try:
67-
post = frontmatter.load(src_file)
68-
except Exception:
69-
return True
70-
title = str(post.get("title", ""))
7163
# If corresponding EN file already exists, skip
72-
en_filename = to_en_filename(src_file, title or src_file.stem)
64+
en_filename = to_en_filename(src_file)
7365
if en_filename.exists():
7466
return False
7567
# If any file on the same date exists in _posts_en, we might have different slug; check by date
@@ -160,8 +152,8 @@ def main() -> int:
160152
if "title" not in fm or not fm["title"]:
161153
fm["title"] = dict(post).get("title", "")
162154

163-
# Construct english filename from translated title
164-
en_path = to_en_filename(src, str(fm.get("title", src.stem)))
155+
# Construct English filename by preserving the original filename
156+
en_path = to_en_filename(src)
165157
en_post = frontmatter.Post(body, **fm)
166158
with open(en_path, "w", encoding="utf-8") as f:
167159
f.write(frontmatter.dumps(en_post))

0 commit comments

Comments
 (0)