check translations updated - working

This commit is contained in:
Brian Read 2024-07-21 11:47:14 +01:00
parent 06c97339d6
commit 2b5006ff0f

View File

@ -2,43 +2,49 @@ import os
import argparse import argparse
def find_lex_files(modulename): 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_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}/" 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 # Get all .lex files in the specified directory
lex_files = [f for f in os.listdir(base_locale_path) if f.endswith('.lex')] lex_files = [f for f in os.listdir(base_locale_path) if f.endswith('.lex')]
# Find the corresponding _en.lex file # Find the corresponding _en.lex file
en_file = next((f for f in os.listdir(base_en_path) if f.endswith('._en.lex')), None) en_file = next((f for f in os.listdir(base_en_path) if f.endswith('_en.lex')), None)
# Assuming the _en.lex file exists # Assuming the _en.lex file exists
if en_file is None: if en_file is None:
print(f"No _en.lex file found for module: {modulename}") print(f"No _en.lex file found for module: {modulename}")
return return
# Read translation pairs from the _en file # Read translation pairs from the _en file
translations = {} translations = {}
with open(os.path.join(base_en_path, en_file), 'r', encoding='utf-8') as en_f: with open(os.path.join(base_en_path, en_file), 'r', encoding='utf-8') as en_f:
for line in en_f: for line in en_f:
if '=>' in line: if '=>' in line:
key, message = line.split('=>', 1) key, message = line.split('=>', 1)
translations[key.strip().strip("'")] = message.strip().strip(",").strip("'") translations[key.strip().strip("'")] = message.strip().strip(",").strip("'")
# Compare against each lex file in the locale directory # Compare against each lex file in the locale directory
for lex_file in lex_files: for lex_file in lex_files:
with open(os.path.join(base_locale_path, lex_file), 'r', encoding='utf-8') as loc_f: #Skip any english lang file in there (there might be one)
for line in loc_f: if lex_file.endswith('_en.lex'):
if '=>' in line: continue
key, message = line.split('=>', 1) with open(os.path.join(base_locale_path, lex_file), 'r', encoding='utf-8') as loc_f:
key = key.strip().strip("'") print(f"File:{lex_file}")
message = message.strip().strip(",").strip("'") 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 # Checking for missing translations
if key in translations: language_code = lex_file.split('.')[0][-2:] # Extracting language code from filename
if message == translations[key] or message == '': #print(f"{lex_file} {language_code}")
language_code = lex_file.split('.')[-2] # Extracting language code from filename #quit()
print(f"Missing translation in module '{modulename}', language '{language_code}', key '{key}'") if key in translations:
else: if message == translations[key] or message == '':
print(f"Key '{key}' not found in _en.lex for module '{modulename}'.") print(f"Missing translation in module '{modulename}', ({language_code})', key '{key}'")
else:
print(f"Key '{key}' not found in english lex for module '{modulename} ({language_code})'.")
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Check for missing translations in lex files.") parser = argparse.ArgumentParser(description="Check for missing translations in lex files.")