Skip to content

Commit

Permalink
Merge branch 'develop' into feat/DropdownForTime
Browse files Browse the repository at this point in the history
  • Loading branch information
VaibhavTalkhande authored Jan 2, 2024
2 parents 22f8810 + 31ac00c commit 08cb1b3
Show file tree
Hide file tree
Showing 37 changed files with 2,075 additions and 345 deletions.
170 changes: 170 additions & 0 deletions .github/workflows/compare_translations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
"""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()
26 changes: 26 additions & 0 deletions .github/workflows/pull-requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,32 @@ jobs:
if: steps.changed-files.outputs.only_changed != 'true'
run: npm run typecheck


- name: Run linting check
if: steps.changed-files.outputs.only_changed != 'true'
run: npm run lint:check

- name: Compare translation files
run: |
chmod +x .github/workflows/compare_translations.py
python .github/workflows/compare_translations.py --directory public/locales
Test-Application:
name: Test Application
runs-on: ubuntu-latest
needs: [Code-Quality-Checks]
steps:
- name: Checkout the Repository
uses: actions/checkout@v3

- name: Install Dependencies
run: npm install --legacy-peer-deps

- name: Get changed TypeScript files
id: changed-files
uses: tj-actions/changed-files@v40

- name: Run tests
if: steps.changed-files.outputs.only_changed != 'true'
run: npm run test -- --watchAll=false --coverage
Expand Down
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
npm run format:fix
npm run lint:fix
npm run typecheck
npm run update:toc

git add .
18 changes: 18 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Contributor Covenant Code of Conduct

# Table of Contents

<!-- toc -->

- [Our Pledge](#our-pledge)
- [Our Standards](#our-standards)
- [Enforcement Responsibilities](#enforcement-responsibilities)
- [Scope](#scope)
- [Enforcement](#enforcement)
- [Enforcement Guidelines](#enforcement-guidelines)
- [1. Correction](#1-correction)
- [2. Warning](#2-warning)
- [3. Temporary Ban](#3-temporary-ban)
- [4. Permanent Ban](#4-permanent-ban)
- [Attribution](#attribution)

<!-- tocstop -->

## Our Pledge

We as members, contributors, and leaders pledge to make participation in our
Expand Down
16 changes: 15 additions & 1 deletion CODE_STYLE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Talawa Admin Code Style

For Talawa Admin, most of the rules for the code style have been enforced with ESLint, but this document serves to provide an overview of the Code style used in Talawa Admin and the Rationale behind it.
Expand All @@ -7,6 +6,21 @@ The code style must be strictly adhered to, to ensure that there is consistency

code style should not be changed and must be followed.

# Table of Contents

<!-- toc -->

- [Tech Stack](#tech-stack)
- [Component Structure](#component-structure)
- [Code Style and Naming Conventions](#code-style-and-naming-conventions)
- [Test and Code Linting](#test-and-code-linting)
- [Folder/Directory Structure](#folderdirectory-structure)
- [Sub Directories of `src`](#sub-directories-of-src)
- [Imports](#imports)
- [Customising Bootstrap](#customising-bootstrap)

<!-- tocstop -->

## Tech Stack

- Typescript
Expand Down
26 changes: 14 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ If you are new to contributing to open source, please read the Open Source Guide

## Table of Contents

- [Contributing to Talawa-Admin](#contributing-to-talawa-admin)
- [Table of Contents](#table-of-contents)
- [Code of Conduct](#code-of-conduct)
- [Ways to Contribute](#ways-to-contribute)
- [Our Development Process](#our-development-process)
- [Issues](#issues)
- [Pull Requests](#pull-requests)
- [Branching Strategy](#branching-strategy)
- [Conflict Resolution](#conflict-resolution)
- [Contributing Code](#contributing-code)
- [Internships](#internships)
- [Community](#community)
<!-- toc -->

- [Code of Conduct](#code-of-conduct)
- [Ways to Contribute](#ways-to-contribute)
- [Our Development Process](#our-development-process)
- [Issues](#issues)
- [Pull Requests](#pull-requests)
- [Branching Strategy](#branching-strategy)
- [Conflict Resolution](#conflict-resolution)
- [Contributing Code](#contributing-code)
- [Internships](#internships)
- [Community](#community)

<!-- tocstop -->

## Code of Conduct

Expand Down
11 changes: 11 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Documentation
Welcome to our documentation guide. Here are some useful tips you need to know!

# Table of Contents

<!-- toc -->

- [Where to find our documentation](#where-to-find-our-documentation)
- [How to use Docusaurus](#how-to-use-docusaurus)
- [Other information](#other-information)

<!-- tocstop -->

## Where to find our documentation

Our documentation can be found in ONLY TWO PLACES:
Expand Down
Loading

0 comments on commit 08cb1b3

Please sign in to comment.