From 342608403c4636b844c81a9839d3526f7bb47a13 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 13 Jul 2026 18:20:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20merge=5Fbricks=5Fi18n.py=20=E5=90=88?= =?UTF-8?q?=E5=B9=B6bricks=E7=BF=BB=E8=AF=91=E5=88=B0=E5=85=A8=E5=B1=80i18?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/merge_bricks_i18n.py | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 scripts/merge_bricks_i18n.py diff --git a/scripts/merge_bricks_i18n.py b/scripts/merge_bricks_i18n.py new file mode 100644 index 0000000..9870f78 --- /dev/null +++ b/scripts/merge_bricks_i18n.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +"""Merge bricks i18n entries into global Sage i18n.json. + +Usage: + python3 merge_bricks_i18n.py /path/to/bricks/i18n /path/to/sage/wwwroot/i18n + +Reads bricks/i18n/{lang}/i18n.json and merges new keys into +sage/wwwroot/i18n/{lang}/i18n.json for all languages. +""" + +import json, sys, os + +LANGUAGES = ['zh', 'en', 'jp', 'ko'] + +def merge(bricks_i18n_dir, sage_i18n_dir): + for lang in LANGUAGES: + brick_path = os.path.join(bricks_i18n_dir, lang, 'i18n.json') + sage_path = os.path.join(sage_i18n_dir, lang, 'i18n.json') + + if not os.path.exists(brick_path): + print(f" skip {lang}: bricks i18n.json not found") + continue + + with open(brick_path) as f: + brick_msgs = json.load(f) + + with open(sage_path) as f: + sage_msgs = json.load(f) + + added = 0 + for k, v in brick_msgs.items(): + if k not in sage_msgs: + sage_msgs[k] = v + added += 1 + + with open(sage_path, 'w') as f: + json.dump(sage_msgs, f, ensure_ascii=False, indent='\t') + print(f" {lang}: {len(sage_msgs)} entries (+{added} from bricks)") + + +if __name__ == '__main__': + if len(sys.argv) != 3: + print(__doc__) + sys.exit(1) + print(f"Merging {sys.argv[1]} -> {sys.argv[2]}") + merge(sys.argv[1], sys.argv[2]) + print("Done")