import xml.etree.ElementTree as ET import os import sys def create_lex_file(lang_code): # Construct the file names based on the language code xml_file_path = ( f"/home/brianr/SME11/etc/e-smith/locale/{lang_code}/FormMagick/general" ) # lex_file_path = f'/usr/share/smanager/lib/SrcMngr/I18N/Modules/General/general_{lang_code}.lex' lex_file_path = f"general_{lang_code}.lex" # Check if the XML file exists if not os.path.exists(xml_file_path): print(f"Error: The file {xml_file_path} does not exist.") return # Parse the XML file tree = ET.parse(xml_file_path) root = tree.getroot() # Open the .lex file for writing with open(lex_file_path, "w", encoding="utf-8") as lex_file: # Iterate over each entry in the lexicon for entry in root.findall("entry"): base = entry.find("base").text trans = entry.find("trans").text # Write to the .lex file in the specified format lex_file.write(f"'{base}' => '{trans}',\n") print(f"The .lex file has been created at {lex_file_path}") if __name__ == "__main__": if len(sys.argv) != 2: print("Usage: python create_lex_file.py ") sys.exit(1) language_code = sys.argv[1] create_lex_file(language_code)