From 5771e6d8c55f89a2c3ba6a7c4d68e458c9102e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jim=20Liu=20=E5=AE=9D=E7=8E=89?= Date: Fri, 6 Mar 2026 23:38:27 -0600 Subject: [PATCH] feat(baoyu-translate): add external glossary files and frontmatter transformation Support glossary_files in EXTEND.md for loading glossaries from external markdown tables or YAML files. Add frontmatter transformation rules to rename source metadata fields with source prefix during translation. --- skills/baoyu-translate/SKILL.md | 5 ++- .../references/config/extend-schema.md | 40 +++++++++++++++++-- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/skills/baoyu-translate/SKILL.md b/skills/baoyu-translate/SKILL.md index cf725c7..069423b 100644 --- a/skills/baoyu-translate/SKILL.md +++ b/skills/baoyu-translate/SKILL.md @@ -41,7 +41,7 @@ if (Test-Path "$HOME/.baoyu-skills/baoyu-translate/EXTEND.md") { "user" } | Found | Read, parse, apply settings. On first use in session, briefly remind: "Using preferences from [path]. You can edit EXTEND.md to customize glossary, audience, etc." | | Not found | **MUST** run first-time setup (see below) — do NOT silently use defaults | -**EXTEND.md Supports**: Default target language | Default mode | Target audience | Custom glossaries | Translation style | Chunk settings +**EXTEND.md Supports**: Default target language | Default mode | Target audience | Custom glossaries (inline or file path) | Translation style | Chunk settings Schema: [references/config/extend-schema.md](references/config/extend-schema.md) @@ -135,7 +135,7 @@ Custom audience descriptions are also accepted, e.g., `--audience "AI感兴趣 1.2 Load built-in glossary for the language pair if available: - EN→ZH: [references/glossary-en-zh.md](references/glossary-en-zh.md) -1.3 Merge glossaries: EXTEND.md glossary + built-in glossary + `--glossary` file (CLI overrides all) +1.3 Merge glossaries: EXTEND.md `glossary` (inline) + EXTEND.md `glossary_files` (external files, paths relative to EXTEND.md location) + built-in glossary + `--glossary` file (CLI overrides all) ### Step 2: Materialize Source & Create Output Directory @@ -201,6 +201,7 @@ Before translating chunks: - **Natural flow**: Use idiomatic target language word order and sentence patterns; break or restructure sentences freely when the source structure doesn't work naturally in the target language - **Terminology**: Use standard translations; annotate with original term in parentheses on first occurrence - **Preserve format**: Keep all markdown formatting (headings, bold, italic, images, links, code blocks) +- **Frontmatter transformation**: If the source has YAML frontmatter, preserve it in the translation with these changes: (1) Rename metadata fields that describe the *source* article — `url`→`sourceUrl`, `title`→`sourceTitle`, `description`→`sourceDescription`, `author`→`sourceAuthor`, `date`→`sourceDate`, and any similar origin-metadata fields — by adding a `source` prefix (camelCase). (2) Translate the values of text fields (title, description, etc.) and add them as new top-level fields. (3) Keep other fields (tags, categories, custom fields) as-is, translating their values where appropriate - **Respect original**: Maintain original meaning and intent; do not add, remove, or editorialize — but sentence structure and imagery may be adapted freely to serve the meaning - **Translator's notes**: For terms, concepts, or cultural references that target readers may not understand — due to jargon, cultural gaps, or domain-specific knowledge — add a concise explanatory note in parentheses immediately after the term. The note should explain *what it means* in plain language, not just provide the English original. Format: `译文(English original,通俗解释)`. Calibrate annotation depth to the target audience: general readers need more notes than technical readers. Only add notes where genuinely needed; do not over-annotate obvious terms. diff --git a/skills/baoyu-translate/references/config/extend-schema.md b/skills/baoyu-translate/references/config/extend-schema.md index 059c19d..d6367d1 100644 --- a/skills/baoyu-translate/references/config/extend-schema.md +++ b/skills/baoyu-translate/references/config/extend-schema.md @@ -25,6 +25,7 @@ chunk_max_words: 5000 # Custom glossary (merged with built-in glossary) # CLI --glossary flag overrides these +# Supports inline entries and/or file paths glossary: - from: "Reinforcement Learning" to: "强化学习" @@ -32,6 +33,14 @@ glossary: to: "Transformer" note: "Keep English" +# Load glossary from external file(s) +# Supports absolute path or relative to EXTEND.md location +# File format: markdown table with | from | to | note | columns, +# or YAML list of {from, to, note} entries +glossary_files: + - ./my-glossary.md + - /path/to/shared-glossary.yaml + # Language-pair specific glossaries glossaries: en-zh: @@ -52,7 +61,8 @@ glossaries: | `style` | string | `storytelling` | Translation style (`storytelling` / `formal` / `technical` / `literal` / `academic` / `business` / `humorous` / `conversational` / `elegant` / custom) | | `chunk_threshold` | number | `4000` | Word count threshold to trigger chunked translation | | `chunk_max_words` | number | `5000` | Max words per chunk | -| `glossary` | array | `[]` | Universal glossary entries | +| `glossary` | array | `[]` | Universal glossary entries (inline) | +| `glossary_files` | array | `[]` | External glossary file paths (absolute or relative to EXTEND.md) | | `glossaries` | object | `{}` | Language-pair specific glossary entries | ## Glossary Entry @@ -63,11 +73,35 @@ glossaries: | `to` | yes | Target translation | | `note` | no | Usage note (e.g., "Keep English", "Only in tech context") | +## Glossary File Format + +External glossary files (`glossary_files`) support two formats: + +**Markdown table** (`.md`): +```markdown +| from | to | note | +|------|----|------| +| Reinforcement Learning | 强化学习 | | +| Transformer | Transformer | Keep English | +``` + +**YAML list** (`.yaml` / `.yml`): +```yaml +- from: "Reinforcement Learning" + to: "强化学习" +- from: "Transformer" + to: "Transformer" + note: "Keep English" +``` + +Paths can be absolute or relative to the EXTEND.md file location. + ## Priority 1. CLI `--glossary` file entries 2. EXTEND.md `glossaries[pair]` entries -3. EXTEND.md `glossary` entries -4. Built-in glossary (e.g., `references/glossary-en-zh.md`) +3. EXTEND.md `glossary` entries (inline) +4. EXTEND.md `glossary_files` entries (in listed order, later files override earlier) +5. Built-in glossary (e.g., `references/glossary-en-zh.md`) Later entries override earlier ones for the same source term.