From 7ec9d64b5b469d172160982fc6ec94741913a674 Mon Sep 17 00:00:00 2001 From: BruceChen Date: Tue, 7 Apr 2026 21:11:07 +0800 Subject: [PATCH 1/2] refactor: optimize translation unit handling in Crowdin script - Introduced a new variable to track successfully translated units, improving clarity and efficiency in the processing logic. - Updated the logic for combining existing and new translation units, ensuring accurate output and preventing unnecessary uploads when no new translations are available. --- tools/translate_crowdin.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/translate_crowdin.py b/tools/translate_crowdin.py index 73e980c7..ad300e57 100644 --- a/tools/translate_crowdin.py +++ b/tools/translate_crowdin.py @@ -775,11 +775,13 @@ def process_language( f"source={u.source[:200]}\n") log.info(" Error details written to %s", err_path) + new_success = [u for u in translated_units if u.translated] + if already_done and output_file.exists(): existing_units = _parse_existing_output(output_file) - all_units = existing_units + [u for u in translated_units if u.translated] + all_units = existing_units + new_success else: - all_units = [u for u in translated_units if u.translated] + all_units = new_success if not all_units: if interrupted: @@ -793,8 +795,10 @@ def process_language( output_file.write_text(xliff_content, encoding="utf-8") log.info(" Written: %s (%d units)", output_file.name, len(all_units)) - if not skip_upload and not interrupted: + if not skip_upload and not interrupted and new_success: upload_xliff(output_file, crowdin_lang) + elif not new_success: + log.info(" No new translations this run, skipping upload") if interrupted: raise KeyboardInterrupt From 698a5621565f073ac50f70ef58522664eb077654 Mon Sep 17 00:00:00 2001 From: BruceChen Date: Wed, 8 Apr 2026 01:29:32 +0800 Subject: [PATCH 2/2] refactor: update output directory handling in Crowdin translation script - Removed the default output directory constant and updated the logic to set the output directory based on the provided argument or default to a "translated" subdirectory within the bundle directory. - Improved help text for the output directory argument to clarify its default behavior. --- tools/translate_crowdin.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/translate_crowdin.py b/tools/translate_crowdin.py index ad300e57..39c76679 100644 --- a/tools/translate_crowdin.py +++ b/tools/translate_crowdin.py @@ -36,7 +36,6 @@ NS = {"x": XLIFF_NS} REPO_ROOT = Path(__file__).resolve().parent.parent WORK_DIR = REPO_ROOT / ".crowdin-translate" BUNDLES_DIR = WORK_DIR / "bundles" -DEFAULT_OUTPUT_DIR = WORK_DIR / "translated" ERRORS_DIR = WORK_DIR / "errors" DOMAIN_PROMPT_CACHE_DIR = WORK_DIR / "domain-prompt-cache" @@ -876,7 +875,7 @@ def build_parser() -> argparse.ArgumentParser: p.add_argument("--skip-upload", action="store_true", help="Skip uploading translations to Crowdin") p.add_argument("--output-dir", type=Path, default=None, - help=f"Output directory (default: {DEFAULT_OUTPUT_DIR})") + help="Output directory (default: /translated/)") p.add_argument("--include-docs", action="store_true", help="Include /docs/ files in translation (skipped by default)") p.add_argument("-v", "--verbose", action="store_true", @@ -927,8 +926,12 @@ def main() -> None: else: bundle_dir = download_bundle(args.bundle_id) - output_dir = args.output_dir or DEFAULT_OUTPUT_DIR + if args.output_dir: + output_dir = args.output_dir + else: + output_dir = bundle_dir / "translated" output_dir.mkdir(parents=True, exist_ok=True) + log.info("Output directory: %s", output_dir) exclude_paths: list[str] | None = None if args.include_docs else ["/docs/"] if exclude_paths: