From 0bbc45a92d9942eeada36dc2a6e966fa41a56e5d Mon Sep 17 00:00:00 2001 From: 1010varun Date: Sat, 30 Dec 2023 23:16:46 +0530 Subject: [PATCH 1/8] ci: testing translational files --- .../workflows/compare-translational-files.py | 168 ++++++++++++++++++ .github/workflows/pull-requests.yml | 5 + INSTALLATION.md | 5 +- 3 files changed, 176 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/compare-translational-files.py diff --git a/.github/workflows/compare-translational-files.py b/.github/workflows/compare-translational-files.py new file mode 100644 index 0000000000..6d4a0498c8 --- /dev/null +++ b/.github/workflows/compare-translational-files.py @@ -0,0 +1,168 @@ +""" +Script to encourage more efficient coding practices. + +Methodology: + + Utility for comparing translations between default and other languages. + + This module defines a function to compare two translations + and print any missing keys in the other language's translation. +Attributes: + + FileTranslation : Named tuple to represent a combination of file and missing translations. + + Fields: + - file (str): The file name. + - missing_translations (list): List of missing translations. + +Functions: + compare_translations(default_translation, other_translation): + Compare two translations and print missing keys. + + load_translation(filepath): + Load translation from a file. + + check_translations(): + Load the default translation and compare it with other translations. + + main(): + The main function to run the script. + Parses command-line arguments, checks for the existence of the specified directory, + and then calls check_translations with the provided or default directory. + + +Usage: + This script can be executed to check and print missing + translations in other languages based on the default English translation. + +Example: + python compare_translations.py +NOTE: + This script complies with our python3 coding and documentation standards + and should be used as a reference guide. It complies with: + + 1) Pylint + 2) Pydocstyle + 3) Pycodestyle + 4) Flake8 + +""" +# standard imports +import argparse +import json +import os +import sys +from collections import namedtuple + +# Named tuple for file and missing translations combination +FileTranslation = namedtuple("FileTranslation", ["file", "missing_translations"]) + + +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 (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: + list: A list of detailed error messages for each missing/mismatched key. + """ + errors = [] + + # Check for missing keys in other_translation + for key in default_translation: + if key not in other_translation: + 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 + + + + +def load_translation(filepath): + """Load translation from a file. + + Args: + filepath: Path to the translation file + + Returns: + translation: Loaded translation + """ + with open(filepath, "r", encoding="utf-8") as file: + translation = json.load(file) + return translation + + + +def check_translations(directory): + """Load default translation and compare with other translations. + + Args: + directory (str): The directory containing translation files. + + Returns: + None + """ + 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 + + error_found = False + + for translation_file in 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") + sys.exit(0) + + +def main(): + """ + Parse command-line arguments, check for the existence of the specified directory, + and call check_translations with the provided or default directory. + + """ + parser = argparse.ArgumentParser( + description="Check and print missing translations for all non-default languages." + ) + parser.add_argument( + "--directory", + type=str, + nargs="?", + default=os.path.join(os.getcwd(), "public/locales"), + help="Directory containing translation files(relative to the root directory).", + ) + args = parser.parse_args() + + if not os.path.exists(args.directory): + print(f"Error: The specified directory '{args.directory}' does not exist.") + sys.exit(1) + + check_translations(args.directory) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/.github/workflows/pull-requests.yml b/.github/workflows/pull-requests.yml index cbff57c090..cae6b02081 100644 --- a/.github/workflows/pull-requests.yml +++ b/.github/workflows/pull-requests.yml @@ -51,6 +51,11 @@ jobs: if: steps.changed-files.outputs.only_changed != 'true' run: npm run lint:check + - name: Compare translation files + run: | + chmod +x .github/workflows/compare-translation-files.py + python .github/workflows/compare-translation-files.py --directory public/locales + Test-Application: name: Test Application diff --git a/INSTALLATION.md b/INSTALLATION.md index 1a7028dfab..a628a75d28 100644 --- a/INSTALLATION.md +++ b/INSTALLATION.md @@ -10,6 +10,7 @@ This document provides instructions on how to set up and start a running instanc - [Installation](#installation) - [Setting up this repository](#setting-up-this-repository) - [Setting up npm](#setting-up-npm) + - [Setting up Typescript](#setting-up-typescript) - [Installing required packages/dependencies](#installing-required-packagesdependencies) - [Configuration](#configuration) - [Creating .env file](#creating-env-file) @@ -25,8 +26,8 @@ This document provides instructions on how to set up and start a running instanc - [Debugging tests](#debugging-tests) - [Linting code files](#linting-code-files) - [Husky for Git Hooks](#husky-for-git-hooks) - - [pre-commit hook](#pre-commit-hook) - - [post-merge hook](#post-merge-hook) + - [pre-commit hook](#pre-commit-hook) + - [post-merge hook](#post-merge-hook) From 838467c8641cf12f114b349958cda8378b1b2b46 Mon Sep 17 00:00:00 2001 From: 1010varun Date: Sat, 30 Dec 2023 23:21:55 +0530 Subject: [PATCH 2/8] ci: testing compare translational files --- .github/workflows/pull-requests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-requests.yml b/.github/workflows/pull-requests.yml index cae6b02081..53102f459e 100644 --- a/.github/workflows/pull-requests.yml +++ b/.github/workflows/pull-requests.yml @@ -51,7 +51,7 @@ jobs: if: steps.changed-files.outputs.only_changed != 'true' run: npm run lint:check - - name: Compare translation files + - name: Compare translation files testing run: | chmod +x .github/workflows/compare-translation-files.py python .github/workflows/compare-translation-files.py --directory public/locales From 042c0283e11c856c72fe1d898c746c3c3624cce1 Mon Sep 17 00:00:00 2001 From: 1010varun Date: Sat, 30 Dec 2023 23:26:19 +0530 Subject: [PATCH 3/8] ci: testing --- .github/workflows/pull-requests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-requests.yml b/.github/workflows/pull-requests.yml index 53102f459e..9878455021 100644 --- a/.github/workflows/pull-requests.yml +++ b/.github/workflows/pull-requests.yml @@ -53,8 +53,8 @@ jobs: - name: Compare translation files testing run: | - chmod +x .github/workflows/compare-translation-files.py - python .github/workflows/compare-translation-files.py --directory public/locales + chmod +x .github/workflows/compare-translational-files.py + python .github/workflows/compare-translational-files.py --directory public/locales Test-Application: From 8ee84d23a10ad1cf8c01fb25045126c6b63c0f27 Mon Sep 17 00:00:00 2001 From: 1010varun Date: Sat, 30 Dec 2023 23:48:32 +0530 Subject: [PATCH 4/8] ci: workflow for translation files --- .github/workflows/pull-requests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-requests.yml b/.github/workflows/pull-requests.yml index 9878455021..9430126b5e 100644 --- a/.github/workflows/pull-requests.yml +++ b/.github/workflows/pull-requests.yml @@ -51,7 +51,7 @@ jobs: if: steps.changed-files.outputs.only_changed != 'true' run: npm run lint:check - - name: Compare translation files testing + - name: Compare translation files run: | chmod +x .github/workflows/compare-translational-files.py python .github/workflows/compare-translational-files.py --directory public/locales From 4f475ed35fb40dee632926a04739f748a0aad5ac Mon Sep 17 00:00:00 2001 From: 1010varun Date: Sun, 31 Dec 2023 00:37:39 +0530 Subject: [PATCH 5/8] refactor: removed unwanted changes From 9ca48a7bea93ac803598428c0d0b865d53ef5bd6 Mon Sep 17 00:00:00 2001 From: 1010varun Date: Sun, 31 Dec 2023 00:41:09 +0530 Subject: [PATCH 6/8] refactor: removed unnecessary lines From 16e2ae58be5091b07971c070ea7b499256941c12 Mon Sep 17 00:00:00 2001 From: 1010varun Date: Sun, 31 Dec 2023 20:57:42 +0530 Subject: [PATCH 7/8] fix: fixed all the failing translation file testcases --- public/locales/fr.json | 5 +++++ public/locales/hi.json | 19 ++++++++++++------- public/locales/sp.json | 22 ++++++++++++++-------- public/locales/zh.json | 5 +++++ 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/public/locales/fr.json b/public/locales/fr.json index 0f40a9e7ce..3452e28457 100644 --- a/public/locales/fr.json +++ b/public/locales/fr.json @@ -33,6 +33,11 @@ "eventCardSeeAll": "Voir Tout", "noEvents": "Aucun événement à venir" }, + "latestPosts": { + "latestPostsTitle": "Dernières Publications", + "seeAllLink": "Voir Tout", + "noPostsCreated": "Aucune Publication Créée" + }, "listNavbar": { "talawa_portal": "Portail D'Administrateur Talawa", "roles": "Les rôles", diff --git a/public/locales/hi.json b/public/locales/hi.json index cb13f29bc2..d24bfb656e 100644 --- a/public/locales/hi.json +++ b/public/locales/hi.json @@ -33,6 +33,11 @@ "eventCardSeeAll": "सभी देखें", "noEvents": "कोई आगामी घटनाएँ नहीं" }, + "latestPosts": { + "latestPostsTitle": "नवीनतम पोस्ट", + "seeAllLink": "सभी देखें", + "noPostsCreated": "कोई पोस्ट नहीं बनाई गई" + }, "listNavbar": { "talawa_portal": "तलावा प्रशासन पोर्टल", "roles": "भूमिकाएँ", @@ -681,14 +686,14 @@ "selectContact": "बातचीत शुरू करने के लिए एक संपर्क चुनें", "sendMessage": "मेसेज भेजें" }, - "ऑर्गप्रोफ़ाइलफ़ील्ड": { - "लोड हो रहा है": "लोड हो रहा है...", - "noCustomField": "कोई कस्टम फ़ील्ड उपलब्ध नहीं", - "customFieldName": "फ़ील्ड नाम", - "enterCustomFieldName": "फ़ील्ड नाम दर्ज करें", - "customFieldType": "फ़ील्ड प्रकार", + "orgProfileField": { + "loading": "लोड हो रहा है...", + "noCustomField": "कोई कस्टम फ़ील्ड उपलब्ध नहीं है", + "customFieldName": "फ़ील्ड का नाम", + "enterCustomFieldName": "फ़ील्ड का नाम दर्ज करें", + "customFieldType": "फ़ील्ड का प्रकार", "saveChanges": "परिवर्तन सहेजें", - "कस्टम फ़ील्ड हटाएँ": "कस्टम फ़ील्ड हटाएँ", + "Remove Custom Field": "कस्टम फ़ील्ड हटाएँ", "fieldSuccessMessage": "फ़ील्ड सफलतापूर्वक जोड़ा गया", "fieldRemovalSuccess": "फ़ील्ड सफलतापूर्वक हटा दिया गया" } diff --git a/public/locales/sp.json b/public/locales/sp.json index 0064c4a149..ac6524a234 100644 --- a/public/locales/sp.json +++ b/public/locales/sp.json @@ -33,6 +33,11 @@ "eventCardSeeAll": "Ver Todos", "noEvents": "No Hay Eventos Próximos" }, + "latestPosts": { + "latestPostsTitle": "Últimas Publicaciones", + "seeAllLink": "Ver Todo", + "noPostsCreated": "No se han creado publicaciones" + }, "listNavbar": { "talawa_portal": "Portal De Administración Talawa", "roles": "Roles", @@ -681,15 +686,16 @@ "selectContact": "Seleccione un contacto para iniciar una conversación", "sendMessage": "Enviar mensaje" }, - "campoPerfildeOrganización": { - "cargando": "Cargando...", + + "orgProfileField": { + "loading": "Cargando..", "noCustomField": "No hay campos personalizados disponibles", - "customFieldName": "Nombre de campo", - "enterCustomFieldName": "Ingrese el nombre del campo", - "customFieldType": "Tipo de campo", - "saveChanges": "Guardar cambios", - "Eliminar campo personalizado": "Eliminar campo personalizado", - "fieldSuccessMessage": "Campo agregado exitosamente", + "customFieldName": "Nombre del Campo", + "enterCustomFieldName": "Ingrese el Nombre del Campo", + "customFieldType": "Tipo de Campo", + "saveChanges": "Guardar Cambios", + "Remove Custom Field": "Eliminar Campo Personalizado", + "fieldSuccessMessage": "Campo añadido exitosamente", "fieldRemovalSuccess": "Campo eliminado exitosamente" } } diff --git a/public/locales/zh.json b/public/locales/zh.json index e90c7d82e6..bcfd073562 100644 --- a/public/locales/zh.json +++ b/public/locales/zh.json @@ -33,6 +33,11 @@ "eventCardSeeAll": "查看全部", "noEvents": "暂无即将举行的活动" }, + "latestPosts": { + "latestPostsTitle": "最新文章", + "seeAllLink": "查看全部", + "noPostsCreated": "暂无文章" + }, "listNavbar": { "talawa_portal": "塔拉瓦管理門戶", "roles": "角色", From 97fb7ac8c930050bb80a763a4886284235433f0f Mon Sep 17 00:00:00 2001 From: 1010varun Date: Mon, 1 Jan 2024 00:18:42 +0530 Subject: [PATCH 8/8] fix: fixed file names --- ...ional-files.py => compare_translations.py} | 38 ++++++++++--------- .github/workflows/pull-requests.yml | 4 +- 2 files changed, 22 insertions(+), 20 deletions(-) rename .github/workflows/{compare-translational-files.py => compare_translations.py} (82%) diff --git a/.github/workflows/compare-translational-files.py b/.github/workflows/compare_translations.py similarity index 82% rename from .github/workflows/compare-translational-files.py rename to .github/workflows/compare_translations.py index 6d4a0498c8..f6f22e843c 100644 --- a/.github/workflows/compare-translational-files.py +++ b/.github/workflows/compare_translations.py @@ -1,6 +1,4 @@ -""" -Script to encourage more efficient coding practices. - +"""Script to encourage more efficient coding practices. Methodology: Utility for comparing translations between default and other languages. @@ -9,7 +7,8 @@ and print any missing keys in the other language's translation. Attributes: - FileTranslation : Named tuple to represent a combination of file and missing translations. + FileTranslation : Named tuple to represent a combination + of file and missing translations. Fields: - file (str): The file name. @@ -27,8 +26,9 @@ main(): The main function to run the script. - Parses command-line arguments, checks for the existence of the specified directory, - and then calls check_translations with the provided or default directory. + Parses command-line arguments, checks for the + existence of the specified directory, and then + calls check_translations with the provided or default directory. Usage: @@ -54,18 +54,22 @@ import sys from collections import namedtuple -# Named tuple for file and missing translations combination -FileTranslation = namedtuple("FileTranslation", ["file", "missing_translations"]) +# Named tuple for file and missing +# translations combination +FileTranslation = namedtuple("FileTranslation", + ["file", "missing_translations"]) -def compare_translations(default_translation, other_translation, default_file, other_file): +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 (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. + other_file (str): The name of the other + translation file. Returns: list: A list of detailed error messages for each missing/mismatched key. @@ -77,18 +81,14 @@ def compare_translations(default_translation, other_translation, default_file, o if key not in other_translation: 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 - - def load_translation(filepath): """Load translation from a file. @@ -103,7 +103,6 @@ def load_translation(filepath): return translation - def check_translations(directory): """Load default translation and compare with other translations. @@ -125,7 +124,9 @@ def check_translations(directory): other_translation = load_translation(other_file) # Compare translations and get detailed error messages - errors = compare_translations(default_translation, other_translation, default_file, translation_file) + 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:") @@ -141,7 +142,8 @@ def check_translations(directory): def main(): """ - Parse command-line arguments, check for the existence of the specified directory, + + Parse command-line arguments, check for the existence of the specified directory and call check_translations with the provided or default directory. """ @@ -165,4 +167,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/.github/workflows/pull-requests.yml b/.github/workflows/pull-requests.yml index 9430126b5e..4f58b904f9 100644 --- a/.github/workflows/pull-requests.yml +++ b/.github/workflows/pull-requests.yml @@ -53,8 +53,8 @@ jobs: - name: Compare translation files run: | - chmod +x .github/workflows/compare-translational-files.py - python .github/workflows/compare-translational-files.py --directory public/locales + chmod +x .github/workflows/compare_translations.py + python .github/workflows/compare_translations.py --directory public/locales Test-Application: