Initial toolkit: scripts, references, skills, and term database

This commit is contained in:
iacore
2026-07-10 21:01:02 +08:00
commit ac9e6e3d1f
51 changed files with 5192 additions and 0 deletions
@@ -0,0 +1,41 @@
# Bilingual DJ Format
## Layout
Each pair: source line immediately followed by target line. Blank line separates pairs.
```
source-line
target-line
source-line
target-line
```
NOT:
```
source-line
← WRONG: extra blank between source and target
target-line
```
## Creating initial bilingual from source only
Only non-blank source lines get an empty target placeholder. Blank lines in the
source pass through as-is and serve as natural pair separators.
```
source-A
source-B
```
The blank line between source-A and source-B is an original blank from the
source — do NOT add an extra target+separator for it.
Pitfall: treating blank source lines as content lines creates 3+ consecutive
blank lines (source-blank → target-blank → separator-blank). This is wrong.
## Verification
`non_blank_source_lines × 2 + total_source_lines = bilingual_line_count`
@@ -0,0 +1,13 @@
# Diacritics Convention
When in doubt, search the terms DB and use the highest-priority source's form.
| Rule | Examples |
|---|---|
| No diacritics (default) | `Mahasthamaprapta` (佛教术语), `Yogacarabhumi-Sastra` (经论名), `Guanyin` (佛教术语), `Pabongkhapa` (nti) |
| With diacritics | `Kṣitigarbha` (DoT定稿 uses this form) |
| Sanskrit terms | Keep standard romanization: `bodhicitta`, `bardo`, `Amitabha`, `prajñā` |
The DB uses simplified romanization. DoT定稿 is the authority — if it uses diacritics for a term, follow it. Otherwise strip them.
Pitfall: academic/pedantic diacritics (`Mahāsthāmaprāpta`, `Yogācārabhūmi Śāstra`, `Avalokiteśvara`) are common in general knowledge but wrong per MPI conventions.
@@ -0,0 +1,65 @@
# Markdown to Djot Conversion
When source material arrives as `.docx.md` (pandoc-converted from docx), convert to `.dj` for translation workflows.
## Splitting combined articles
If a single markdown file contains multiple articles (common when docx has two talks in one file), split at the article boundary before converting. Use `sed` by line number:
```bash
sed -n '1,218p' combined.md > a1.md
sed -n '220,282p' combined.md > a2.md
```
## TOC stripping
Pandoc docx→md produces a markdown TOC with tab-separated page numbers:
```markdown
[一、对佛教的感悟\t1](#一、对佛教的感悟)
[二、佛教与人类文明\t5](#二、佛教与人类文明)
```
Strip before conversion:
```bash
sed -i '/^\[.*\t.*\](#.*)$/d' input.md
```
Or in Python: skip lines matching `line.startswith("[") and "\t" in line and "](#" in line`.
## Heading anchor cleanup
Pandoc's docx→md conversion adds `{#heading-id}` anchors to every heading:
```markdown
## 1.安宁疗护 {#1.安宁疗护}
```
These must be stripped before markdown→djot conversion, otherwise pandoc's djot writer leaves stray `{#...}` lines in the output:
```bash
sed 's/ {#[^}]*}//g' input.md > clean.md
```
## Conversion command
```bash
pandoc clean.md -f markdown -t djot --wrap=none -o output.dj
```
`--wrap=none` prevents reflow of long paragraphs.
## Post-conversion cleanup
Pandoc may still leave stray `{#...}` lines in djot output. Remove them:
```bash
sed -i '/^{#.*}$/d' output.dj
```
## Pandoc artifacts
- Unicode `——` (U+2014 × 2) → `------` in djot (two em dashes, `---` each). This is correct djot syntax.
- Markdown hard line breaks (trailing ` `) → `\\\n` in djot. Preserves original paragraph structure.
- Pandoc normalizes heading IDs (strips `、` and other punctuation). Ignore; the stray-line cleanup handles it.
@@ -0,0 +1,43 @@
# Meditation / Mindfulness Content Translation
When the source is a guided meditation script, exercise guide, posture instruction,
or breathing practice (rather than a Dharma talk, sutra commentary, or teaching text),
use a lighter workflow than the full dharma-translation pipeline.
## Register
Default to warm, direct instructional voice (Thầy-adjacent):
- Second-person address ("you")
- Concrete images, sensory details
- Oral rhythm, short sentences
- Present tense, imperative mood
MB corpus consultation is NOT needed for register — this content type has its own
well-established English conventions (yoga/meditation instructional voice).
## Terms
Terms DB lookup for Buddhist-mindfulness vocabulary is useful but limited to key terms:
- 正念 → mindfulness
- 觉知 → awareness
- 无我 → depends on context: "non-self" for philosophical/Dharma content; "selflessly" for embodied/movement instruction where the sense is no separate controller imposing on the action
- 中道 → Middle Way
- 丹田 → dantian (keep as-is; well-known in meditation/qigong)
Context-sensitive terms:
- 心 (xīn): in meditation/movement contexts it often means "mind/attention" not emotional "heart." 持心 means holding the mind with focused attention, not holding with emotion.
- 念 (niàn): mindfulness/attention/recollection — context between these.
- Buddhist philosophical terms (无我, 空, 缘起) in non-philosophical contexts (movement instruction, body scans) may need practical/concrete translations rather than doctrinal ones.
Skip deep terms alignment unless dense Dharma vocabulary (emptiness, dependent origination,
Buddha-nature, etc.) appears in the text.
## Comparison files
Still create 对照.dj as usual. See comparison file format in this skill.
## Pitfalls
- **Don't add formatting the source doesn't have**: sub-section labels using `【】` in Chinese should become plain `[label]` in English, not `*[label]*` or `**[label]**`. Match the source's formatting level exactly.
- **`**text**` is Markdown, not Djot**: Djot emphasis uses single asterisks (`*text*`). Never use double asterisks in `.dj` files.
- **心 ≠ heart by default**: in meditation/movement contexts, 持心 = holding the mind with attention, not holding with emotion. Translate based on context, not dictionary defaults.
@@ -0,0 +1,50 @@
# PDF-vs-DOCX Proofread Workflow
Compare typeset PDF against the authoritative DOCX manuscript. Catch
discrepancies introduced during typesetting: dropped words, terminology
drift, repositioned phrases, extra content.
## Pattern
The existing `scripts/proofread-pdf.py` is article-specific (hardcoded to
佛教徒的人生态度). For each new article, create a similarly-shaped script:
```
translate-files/<article>/<name>-<hash>.py
```
Hash = `md5('translate-files/<article>')[:6]`
## Script Structure
1. Convert DOCX to plain text: `pandoc docx -f docx -t plain --wrap=none`
2. Convert PDF to plain text: `pdftotext -layout pdf`
3. Extract body from DOCX — find body start marker (first sentence of body)
4. Extract body from PDF — find same marker, filter out:
- Page slugs: `文章名.*indd \d+`
- Headers: `The Mindful Peace Academy Collection`, article title
- Page numbers: `^\d{1,3}$`
- Section numerals: `^(I|II|III|IV)$`
- Section name lines: `^(Three Basic Elements|...|Conclusion)$`
5. Join hyphenated line breaks (`word-` at end + lowercase continuation)
6. Fix PDF artifacts: `L iving``Living`, `T\s+he``The`
7. Normalize both (collapse whitespace, unify quotes/dashes)
8. Compare with difflib.SequenceMatcher or sentence-level substring search
## Pitfalls
- PDF hyphen joining drops the hyphen: `self-knowing``selfknowing`.
This causes cascading word-level diff failures. Use sentence-level or
chunk-based matching instead of word-by-word comparison.
- Section headers (I, II, III) may be present in DOCX body but filtered
from PDF — not real discrepancies.
- The existing `scripts/proofread-pdf.py` is hardcoded for 佛教徒的人生态度.
Do NOT reuse it for other articles without rewriting the body-start
markers and filter patterns. Create article-specific scripts instead.
- `git diff --word-diff` fails when one file is multi-line and the other
is single-line. Normalize both to single-line first.
## Example
`translate-files/正念禅修十要素/ten-elements-c7fcd9.py` — extracts cleaned
body from both sources, outputs to `/tmp/` for side-by-side diffing.