From 3f5a2663f6dd1960670ca874a9bdfb38db84e26a Mon Sep 17 00:00:00 2001 From: jpirnay Date: Thu, 26 Mar 2026 10:30:14 +0100 Subject: [PATCH] Exit if non-unique identifiers found --- scripts/gen_i18n.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/gen_i18n.py b/scripts/gen_i18n.py index 465737a0..44c1a5d7 100755 --- a/scripts/gen_i18n.py +++ b/scripts/gen_i18n.py @@ -146,6 +146,29 @@ def load_translations( if english_file is None: raise ValueError("No YAML file with _language_code: EN found") + duplicate_orders: Dict[str, List[str]] = {} + order_to_files: Dict[str, List[str]] = {} + for fname, data in parsed.items(): + order = data.get("_order") + if not order: + continue + order_to_files.setdefault(order, []).append(fname) + + for order, files in order_to_files.items(): + if len(files) > 1: + duplicate_orders[order] = sorted(files) + + if duplicate_orders: + duplicate_messages = [ + f"_order {order}: {', '.join(files)}" + for order, files in sorted( + duplicate_orders.items(), key=lambda item: int(item[0]) + ) + ] + raise ValueError( + "Duplicate _order values found:\n " + "\n ".join(duplicate_messages) + "\nEach _order value must be unique to ensure a deterministic language order." + ) + # Order: English first, then by _order metadata (falls back to filename) def sort_key(fname: str) -> Tuple[int, int, str]: """English always first (0), then by _order, then by filename."""