import os import re def check_i18n_keys(project_root): src_dir = os.path.join(project_root, "src") languages_dir = os.path.join(project_root, "languages") rust_key_regex = re.compile(r't!\("([a-zA-Z0-9_.]+)"\)') ftl_key_regex = re.compile(r"^([a-zA-Z0-9_.-]+)\s*=") used_keys = set() defined_keys = set() # Extract keys from Rust files for root, _, files in os.walk(src_dir): for file in files: if file.endswith(".rs"): file_path = os.path.join(root, file) with open(file_path, "r", encoding="utf-8") as f: content = f.read() for match in rust_key_regex.finditer(content): used_keys.add(match.group(1)) # Extract keys from FTL files for root, _, files in os.walk(languages_dir): for file in files: if file.endswith(".ftl"): file_path = os.path.join(root, file) with open(file_path, "r", encoding="utf-8") as f: for line in f: match = ftl_key_regex.match(line) if match: defined_keys.add(match.group(1)) print("--- i18n Key Check Report ---") missing_keys = used_keys - defined_keys if not missing_keys: print("✅ No missing translation keys found in FTL files.") else: print( "❌ Missing translation keys (used in code but not defined in FTL files):" ) for key in sorted(list(missing_keys)): print(f" - {key}") unused_keys = defined_keys - used_keys if not unused_keys: print("✅ No unused translation keys found in FTL files.") else: print("⚠️ Unused translation keys (defined in FTL files but not used in code):") for key in sorted(list(unused_keys)): print(f" - {key}") print("-----------------------------") if __name__ == "__main__": project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) check_i18n_keys(project_root)