import os import argparse def find_lex_files(modulename): base_locale_path = f"/home/brianr/Documents/smeserver-manager-locale/root/usr/share/smanager/lib/SrvMngr/I18n/Modules/{modulename}/" base_en_path = f"/home/brianr/Documents/smeserver-manager/root/usr/share/smanager/lib/SrvMngr/I18n/Modules/{modulename}/" # Get all .lex files in the specified directory lex_files = [f for f in os.listdir(base_locale_path) if f.endswith('.lex')] # Find the corresponding _en.lex file en_file = next((f for f in os.listdir(base_en_path) if f.endswith('._en.lex')), None) # Assuming the _en.lex file exists if en_file is None: print(f"No _en.lex file found for module: {modulename}") return # Read translation pairs from the _en file translations = {} with open(os.path.join(base_en_path, en_file), 'r', encoding='utf-8') as en_f: for line in en_f: if '=>' in line: key, message = line.split('=>', 1) translations[key.strip().strip("'")] = message.strip().strip(",").strip("'") # Compare against each lex file in the locale directory for lex_file in lex_files: with open(os.path.join(base_locale_path, lex_file), 'r', encoding='utf-8') as loc_f: for line in loc_f: if '=>' in line: key, message = line.split('=>', 1) key = key.strip().strip("'") message = message.strip().strip(",").strip("'") # Checking for missing translations if key in translations: if message == translations[key] or message == '': language_code = lex_file.split('.')[-2] # Extracting language code from filename print(f"Missing translation in module '{modulename}', language '{language_code}', key '{key}'") else: print(f"Key '{key}' not found in _en.lex for module '{modulename}'.") if __name__ == "__main__": parser = argparse.ArgumentParser(description="Check for missing translations in lex files.") parser.add_argument("modulename", help="The name of the module to check translations for.") args = parser.parse_args() find_lex_files(args.modulename)