Skip to content

Commit fb68728

Browse files
authored
docstring added, comments added as per copilot suggestion
1 parent 94334fb commit fb68728

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

extras/bundle_translations/apply_translations.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1+
"""Apply translations from CSV back to pyRevit bundle YAML files.
2+
3+
This script reads a CSV file containing translations (generated by
4+
extract_translations.py) and applies them to the corresponding bundle.yaml
5+
files, updating or creating multilingual field dictionaries.
6+
7+
Configuration:
8+
TRANSLATION_CSV: Path to the CSV file containing translations
9+
LANGUAGE_KEY: Translation language key to apply (e.g., 'chinese_s')
10+
SOURCE_LANG: Source language key (default: 'en_us')
11+
"""
112
import csv
213
from pathlib import Path
314
from ruamel.yaml import YAML # pip install ruamel.yaml
415

516
# -------- CONFIG --------
6-
TRANSLATION_CSV = r"C:\temp\translations.csv"
7-
LANGUAGE_KEY = "chinese_s"
8-
SOURCE_LANG = "en_us"
17+
TRANSLATION_CSV = r"C:\temp\translations.csv" # same path as in other script
18+
LANGUAGE_KEY = "chinese_s" # same as in other script
19+
SOURCE_LANG = "en_us" # same as in other script
920
# ------------------------
1021

1122
yaml = YAML()
@@ -98,7 +109,7 @@ def main():
98109
with open(yaml_file, "w", encoding="utf-8") as f:
99110
yaml.dump(data, f)
100111

101-
print(f"[Updating] {yaml_file}")
112+
print(f"[Processing] {yaml_file}")
102113

103114
except Exception as e:
104115
print(f"[ERROR] writing {yaml_file}: {e}")

extras/bundle_translations/extract_translations.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1+
"""Extract translation strings from pyRevit bundle YAML files.
2+
3+
This script scans bundle.yaml files for title and tooltip fields,
4+
extracting English source text and any existing translations to a CSV file
5+
for easier translation workflow.
6+
7+
Configuration:
8+
BASE_DIR: Root directory containing bundle YAML files
9+
OUTPUT_CSV: Path where the CSV file will be written
10+
LANGUAGE_KEY: Translation language key (e.g., 'chinese_s')
11+
SOURCE_LANG: Source language key (default: 'en_us')
12+
"""
113
import os
214
from pathlib import Path
315
from ruamel.yaml import YAML # pip install ruamel.yaml
416
import csv
517

618
# -------- CONFIG --------
7-
BASE_DIR = r"C:\Program Files\pyRevit-Master\extensions\pyRevitTools.extension"
8-
OUTPUT_CSV = r"C:\temp\translations.csv"
19+
BASE_DIR = r"C:\Program Files\pyRevit-Master\extensions\pyRevitTools.extension" # adjust for custom installation
20+
OUTPUT_CSV = r"C:\temp\translations.csv" # same path as in other script
921
LANGUAGE_KEY = "chinese_s" # translation key to extract/merge
1022
SOURCE_LANG = "en_us" # main source language
1123
# ------------------------

0 commit comments

Comments
 (0)