|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import os |
| 6 | +from functools import lru_cache |
6 | 7 | from pathlib import Path |
7 | 8 |
|
| 9 | +import yaml |
8 | 10 | from rich.console import Console |
9 | 11 |
|
10 | 12 | # Paths (resolved relative to this file: _scripts/translate/config.py) |
11 | 13 | REPO_ROOT = Path(__file__).parent.parent.parent |
12 | 14 | DOCS_ROOT = REPO_ROOT / "docs" |
13 | 15 | EN_DOCS = DOCS_ROOT / "en" / "docs" |
14 | 16 | SCRIPTS_DIR = REPO_ROOT / "_scripts" |
| 17 | +TRANSLATE_CONFIG = Path(__file__).parent / "translate_config.yml" |
15 | 18 |
|
16 | 19 | # Claude API settings |
17 | 20 | MODEL = "claude-sonnet-4-6" |
|
28 | 31 | DEFAULT_PARALLEL = 10 |
29 | 32 | PRIORITY_DIRS = ["hello_nextflow", "hello_nf-core", "nf4_science", "envsetup"] |
30 | 33 |
|
| 34 | + |
| 35 | +@lru_cache |
| 36 | +def get_translate_config() -> dict: |
| 37 | + """Load translation configuration from translate_config.yml.""" |
| 38 | + if not TRANSLATE_CONFIG.exists(): |
| 39 | + return {} |
| 40 | + data = yaml.safe_load(TRANSLATE_CONFIG.read_text(encoding="utf-8")) |
| 41 | + return data if isinstance(data, dict) else {} |
| 42 | + |
| 43 | + |
| 44 | +def get_exclude_dirs() -> set[str]: |
| 45 | + """Return the set of directory names to exclude from translation.""" |
| 46 | + cfg = get_translate_config() |
| 47 | + dirs = cfg.get("exclude_dirs", []) |
| 48 | + return set(dirs) if isinstance(dirs, list) else set() |
| 49 | + |
| 50 | + |
31 | 51 | # Comment styles by language (used for code block post-processing) |
32 | 52 | HASH_COMMENT_LANGS = {"python", "py", "sh", "bash", "dockerfile", "yaml", "yml", "toml"} |
33 | 53 | SLASH_COMMENT_LANGS = {"console"} # Note: json has no comments |
|
0 commit comments