Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added check for all translation file #2275

119 changes: 119 additions & 0 deletions .github/workflows/compare_translations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
"""
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 (namedtuple): 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.

check_translations():
Load the default translation and compare it with other translations.

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 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):
"""Compare two translations and print missing keys.

Args:
default_translation: The default translation
other_translation: The other translation

Returns:
missing_translations: List of missing translations
"""
missing_translations = []

for key in default_translation:
if key not in other_translation:
missing_translations.append(key)

return missing_translations


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():
"""Load default translation and compare with other translations."""
default_translation = load_translation("lang/en.json")
translations_dir = "lang"
translations = os.listdir(translations_dir)
translations.remove("en.json") # Exclude default translation

files_with_missing_translations = []

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:
palisadoes marked this conversation as resolved.
Show resolved Hide resolved
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:
sys.exit(1) # Exit with an error status code
else:
print("All translations are present")
sys.exit(0)


if __name__ == "__main__":
check_translations()
# Exit with a success status code
27 changes: 16 additions & 11 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ on:
- 'master'

env:
CODECOV_UNIQUE_NAME: CODECOV_UNIQUE_NAME-${{ github.run_id }}-${{ github.run_number }}
CODECOV_UNIQUE_NAME: CODECOV_UNIQUE_NAME-${{ github.run_id }}-${{ github.run_number }}

jobs:
Flutter-Codebase-Check:
name: Checking codebase
Expand All @@ -27,11 +27,11 @@ jobs:
- uses: actions/checkout@v3
with:
# ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
fetch-depth: 0
- uses: actions/setup-java@v3
with:
distribution: 'zulu' # See 'Supported distributions' for available options
java-version: '12.0'
java-version: '12.0'
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.16.0'
Expand Down Expand Up @@ -66,11 +66,16 @@ jobs:
git checkout temp_branch
pip install GitPython
python ./.github/workflows/check_ignore.py --repository ${{github.repository}} --merge_branch_name ${{github.head_ref}}
- name: Compare translation files
run: |
chmod +x .github/workflows/compare_translations.py
python .github/workflows/compare_translations.py

- name: Analysing codebase for default linting
run: flutter analyze --no-pub
- name: Analysing codebase for custom linting
run: flutter pub run custom_lint
- name : Changed Files
- name: Changed Files
id: changed-files
uses: tj-actions/changed-files@v35
- name: List all changed files
Expand Down Expand Up @@ -104,7 +109,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'zulu' # See 'Supported distributions' for available options
java-version: '12.0'
java-version: '12.0'
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.16.0'
Expand All @@ -118,13 +123,13 @@ jobs:
with:
verbose: true
fail_ci_if_error: false
name: '${{env.CODECOV_UNIQUE_NAME}}'
name: '${{env.CODECOV_UNIQUE_NAME}}'
- name: Test acceptable level of code coverage
uses: VeryGoodOpenSource/very_good_coverage@v2
with:
path: './coverage/lcov.info'
min_coverage: 88.0
path: './coverage/lcov.info'
min_coverage: 88.0

Android-Build:
name: Testing build for android
runs-on: ubuntu-latest
Expand All @@ -134,7 +139,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'zulu' # See 'Supported distributions' for available options
java-version: '12.0'
java-version: '12.0'
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.16.0'
Expand Down
44 changes: 34 additions & 10 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.7.1"
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "41b90ceaec6d79819f31e975e61d479516efe701dea35f891b2f986c1b031422"
url: "https://pub.dev"
source: hosted
version: "9.0.17"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "54808cfcfa87dbc0d74c61ac063d624adf1bd5c0407301f32b06c783c60dc4ca"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: "7e71be3c161472f6c9158ac8875dd8de575060d60b5d159ebca3600ea32c9116"
url: "https://pub.dev"
source: hosted
version: "1.0.6"
lint:
dependency: "direct dev"
description:
Expand All @@ -1033,26 +1057,26 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
url: "https://pub.dev"
source: hosted
version: "0.12.16"
version: "0.12.16+1"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev"
source: hosted
version: "0.5.0"
version: "0.8.0"
meta:
dependency: transitive
description:
name: meta
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
url: "https://pub.dev"
source: hosted
version: "1.10.0"
version: "1.11.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -1137,10 +1161,10 @@ packages:
dependency: transitive
description:
name: path
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
url: "https://pub.dev"
source: hosted
version: "1.8.3"
version: "1.9.0"
path_parsing:
dependency: transitive
description:
Expand Down Expand Up @@ -1834,5 +1858,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.2.0-194.0.dev <3.13.0"
flutter: ">=3.13.0"
dart: ">=3.2.0 <3.13.0"
flutter: ">=3.16.0"
Loading