Skip to content

Commit

Permalink
Script Update: Detailed Error Output for Translation Mismatches (Pali…
Browse files Browse the repository at this point in the history
…sadoesFoundation#2284)

* Verification of Translation Comparison Script Functionality

* testing when default language has 1 extra key

* testing when default language has 1 extra key

* testing when key in DL has different spacing in a key

* testing multiple extra keys in DL

* testing when key is wrong in other translation files

* Modifying script to give more detailed description for the missing or mismatched key

* testing

* testing

* testing

* testing

* more detailed description for error

* testing

* testing if new script displays the correct error for new key that is not present in non default files

* testing for wrong key in non default

* modified compare translation script

* testing

* testing

* modified
  • Loading branch information
Dante291 authored and Abhisheksainii committed Jan 3, 2024
1 parent f0d34ad commit fee00b9
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 53 deletions.
71 changes: 38 additions & 33 deletions .github/workflows/compare_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,35 @@
FileTranslation = namedtuple("FileTranslation", ["file", "missing_translations"])


def compare_translations(default_translation, other_translation):
"""Compare two translations and print missing keys.
def compare_translations(default_translation, other_translation, default_file, other_file):
"""Compare two translations and return detailed info about missing/mismatched keys.
Args:
default_translation: The default translation
other_translation: The other translation
default_translation (dict): The default translation (en.json).
other_translation (dict): The other language translation.
default_file (str): The name of the default translation file.
other_file (str): The name of the other translation file.
Returns:
missing_translations: List of missing translations
list: A list of detailed error messages for each missing/mismatched key.
"""
missing_translations = []
errors = []

# Check for missing keys in other_translation
for key in default_translation:
if key not in other_translation:
missing_translations.append(key)
error_msg = f"Missing Key: '{key}' - This key from '{default_file}' is missing in '{other_file}'."
errors.append(error_msg)

# Check for keys in other_translation that don't match any in default_translation
for key in other_translation:
if key not in default_translation:
error_msg = f"Error Key: '{key}' - This key in '{other_file}' does not match any key in '{default_file}'."
errors.append(error_msg)

return errors


return missing_translations


def load_translation(filepath):
Expand All @@ -95,39 +107,32 @@ def load_translation(filepath):
def check_translations(directory):
"""Load default translation and compare with other translations.
Args:
Args:
directory (str): The directory containing translation files.
Returns:
None
"""
default_translation = load_translation("lang/en.json")
translations_dir = directory
translations = os.listdir(translations_dir)
translations.remove("en.json") # Exclude default translation
default_file = "en.json"
default_translation = load_translation(os.path.join(directory, default_file))
translations = os.listdir(directory)
translations.remove(default_file) # Exclude default translation

files_with_missing_translations = []
error_found = False

for translation_file in translations:
translation_path = os.path.join(translations_dir, translation_file)
other_translation = load_translation(translation_path)

# Compare translations
missing_translations = compare_translations(
default_translation, other_translation
)
if missing_translations:
file_translation = FileTranslation(translation_file, missing_translations)
files_with_missing_translations.append(file_translation)

for file_translation in files_with_missing_translations:
print(
f"File {translations_dir}/{file_translation.file} has missing translations for:"
)
for key in file_translation.missing_translations:
print(f" - {key}")

if files_with_missing_translations:
other_file = os.path.join(directory, translation_file)
other_translation = load_translation(other_file)

# Compare translations and get detailed error messages
errors = compare_translations(default_translation, other_translation, default_file, translation_file)
if errors:
error_found = True
print(f"File {translation_file} has missing translations for:")
for error in errors:
print(f" - {error}")

if error_found:
sys.exit(1) # Exit with an error status code
else:
print("All translations are present")
Expand Down
1 change: 0 additions & 1 deletion lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@
"Logout": "Ausloggen",
"Settings": "Einstellungen",
"Dark Theme": "Dunkles Thema",

"Error": "Fout",
"Warning": "Waarschuwing",
"Information": "Informatie",
Expand Down
7 changes: 0 additions & 7 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"Enter your password": "Enter your password",
"Forgot password": "Forgot password",
"Login": "Login",

"Notification Feature is not installed": "Notification Feature is not installed",
"Sit back relax, we'll": "Sit back relax, we'll",
"Recover": "Recover",
Expand All @@ -35,7 +34,6 @@
"Next": "Next",
"Request Sent to": "Request Sent to",
"Log out": "Log out",

"Error": "Error",
"Warning": "Warning",
"Information": "Information",
Expand All @@ -46,7 +44,6 @@
"Collaborate": "Collaborate",
"with your": "with your",
"Organizations": "Organizations",

"Title from the viewMode GSoC branch": "Title from the viewMode GSoC branch",
"Please verify URL first": "Please verify URL first",
"Enter a valid URL": "Enter a valid URL",
Expand All @@ -61,20 +58,16 @@
"Password must not contain spaces": "Password must not contain spaces",
"Password does not match original": "Password does not match original",
"Join Organisation": "Join Organisation",

"We're": "We're",
"Glad": "Glad",
"you're": "you're",
"Back": "Back",

"Let's": "Let's",
"get": "get",
"you": "you",
"SignUp": "SignUp",

"Please wait": "Please wait",
"for organisation(s) to accept your invitation.": "for organisation(s) to accept your invitation.",

"Add Event Title": "Add Event Title",
"Where is the event": "Where is the event",
"Add Location": "Add Location",
Expand Down
2 changes: 0 additions & 2 deletions lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
"Login": "Acceso",
"Sit back relax, we'll": "Siéntese, ",
"Recover": "",

"Notification Feature is not installed": "La función de notificación no está instalada",

"your password": "relájese, recuperaremos su contraseña",
"Recover Password": "Recupera tu contraseña",
"Select Language": "Seleccione el idioma",
Expand Down
4 changes: 0 additions & 4 deletions lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
"Enter new password": "Entrez un nouveau mot de passe",
"Re-Enter your password": "Entrez à nouveau votre mot de passe",
"Change Password": "Changer le mot de passe",

"Email Hint": "[email protected]",
"Notification Feature is not installed": "La fonction de notification n'est pas installée",

"Enter your registered Email": "Entrez votre email enregistré",
"Enter your password": "Tapez votre mot de passe",
"Forgot password": "Mot de passe oublié",
Expand All @@ -36,7 +34,6 @@
"Next": "Suivante",
"Request Sent to": "Demande envoyée à",
"Log out": "Se déconnecter",

"Join": "Rejoignez",
"and": "et",
"Collaborate": "collaborez",
Expand All @@ -61,7 +58,6 @@
"Password must not contain spaces": "Le mot de passe ne doit pas contenir d'espaces",
"Password does not match original": "Le mot de passe ne correspond pas à l'original",
"Join Organisation": "Rejoindre l'organisation",

"We're": "Nous sommes",
"Glad": "heureux que vous",
"you're": "soyez de",
Expand Down
3 changes: 0 additions & 3 deletions lang/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"Login": "ログイン",
"Sit back relax, we'll": "ゆったりとおくつろぎください。",
"Recover": "回復",

"Notification Feature is not installed": "通知機能がインストールされていません",
"your password": "あなたのパスワード",
"Recover Password": "パスワードを回復",
Expand Down Expand Up @@ -62,10 +61,8 @@
"get": "得る",
"you": "あなた",
"SignUp": "サインアップ",

"Please wait": "お待ちください",
"for organisation(s) to accept your invitation.": "組織があなたの招待を受け入れるために。",

"Add Event Title": "イベントタイトルを追加",
"Where is the event": "イベントはどこですか",
"Add Location": "場所を追加",
Expand Down
2 changes: 0 additions & 2 deletions lang/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
"Forgot password": "Esqueceu sua senha",
"Login": "Conecte-se",
"Sit back relax, we'll": "Sente-se relaxe, vamos",

"Notification Feature is not installed": "O recurso de notificação não está instalado",

"Recover": "Recuperar",
"your password": "sua senha",
"Recover Password": "Recuperar senha",
Expand Down
1 change: 0 additions & 1 deletion lang/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"Sit back relax, we'll": "高枕无忧, ",
"Recover": "",
"Notification Feature is not installed": "未安装通知功能\n",

"your password": "我们会找回您的密码",
"Recover Password": "恢复你的密码",
"Select Language": "选择语言",
Expand Down

0 comments on commit fee00b9

Please sign in to comment.