From b061a07cbde82bf971ff51624aae526cce23977d Mon Sep 17 00:00:00 2001 From: Brian Read Date: Thu, 18 Jul 2024 12:07:36 +0100 Subject: [PATCH] Sort out lack of prefix for General directory --- Lex2Po.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Lex2Po.py b/Lex2Po.py index cef8d45..f635fbb 100644 --- a/Lex2Po.py +++ b/Lex2Po.py @@ -41,10 +41,12 @@ def save_lex_file(entries, lex_file): escaped_value = value.replace("'", "\\'") # Escape single quotes file.write(f"'{key}' => '{escaped_value}',\n") -def infer_prefix(entries, filename): +def infer_prefix(entries, filename,IsGeneral): """ Infer the prefix from entries that contain it, fallback to the first 3 characters of the filename. """ + if IsGeneral: + return "" #No prefix for General items for key in entries.keys(): match = re.match(r"(.*?_)?.*", key) if match: @@ -78,12 +80,12 @@ def ensure_prefix(entries, prefix,file_path): updated_entries[key] = value return updated_entries -def convert_lex_to_po(lex_file, po_file, en_entries, general_en_entries): +def convert_lex_to_po(lex_file, po_file, en_entries, general_en_entries,IsGeneral=False): translated_entries = parse_lex_file(lex_file) language_code = extract_language_from_filename(po_file.name) # Infer prefix from original en_entries and ensure all entries have this prefix - prefix = infer_prefix(en_entries, Path(lex_file)) + prefix = infer_prefix(en_entries, Path(lex_file),IsGeneral) en_entries = ensure_prefix(en_entries, prefix,lex_file) translated_entries = ensure_prefix(translated_entries, prefix,lex_file) @@ -149,10 +151,8 @@ def process_directory_with_en_mapping(source_directory, master_directory): # Apply it to find the corresponding en directory corresponding_en_dir = master_directory / subservient_dir_name - #Skip the General directory as it has not prefix's - if subservient_dir_name == "General": - # and skip to next - continue + #Tag the General directory as it has no prefix's + IsGeneral = subservient_dir_name == "General" # Find corresponding `*`_en.lex` files en_entries = {} @@ -173,7 +173,7 @@ def process_directory_with_en_mapping(source_directory, master_directory): #po_file = po_file.lower().replace("-", "_") print(f"Converting {lex_file} to {po_file}") - convert_lex_to_po(lex_file, po_file, en_entries,general_en_entries) + convert_lex_to_po(lex_file, po_file, en_entries,general_en_entries,IsGeneral) # Save the updated en_entries to the en.lex file in the locale directory if en_entries: