Skip to content

Commit

Permalink
Fixes: Translations Are Not Correctly Tested in Our PR Workflow (#2263)
Browse files Browse the repository at this point in the history
* Added translations for the headings

* Added icons besides member names

* Added tests for checking if image is displayed for existing user

* Added translations in all languages

* modified script to test for nested keys

* Added test to check if profile image is displayed for existing user

* Added missing and extra keys

* added missing key in english translation file

* added translations for zh

* fixed change in compare_translations

* added all translations

* Added test for avartar image

* fixed formatting error

* added more translations after merge
  • Loading branch information
Nandika-A authored Sep 17, 2024
1 parent bb4029d commit e143243
Show file tree
Hide file tree
Showing 7 changed files with 1,381 additions and 324 deletions.
30 changes: 28 additions & 2 deletions .github/workflows/compare_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,31 @@ def compare_translations(default_translation,
errors.append(error_msg)
return errors

def flatten_json(nested_json, parent_key=""):
"""
Flattens a nested JSON, concatenating keys to represent the hierarchy.
Args:
nested_json (dict): The JSON object to flatten.
parent_key (str): The base key for recursion (used to track key hierarchy).
Returns:
dict: A flattened dictionary with concatenated keys.
"""
flat_dict = {}

for key, value in nested_json.items():
# Create the new key by concatenating parent and current key
new_key = f"{parent_key}.{key}" if parent_key else key

if isinstance(value, dict):
# Recursively flatten the nested dictionary
flat_dict.update(flatten_json(value, new_key))
else:
# Assign the value to the flattened key
flat_dict[new_key] = value

return flat_dict

def load_translation(filepath):
"""Load translation from a file.
Expand All @@ -104,7 +129,8 @@ def load_translation(filepath):
if not content.strip():
raise ValueError(f"File {filepath} is empty.")
translation = json.loads(content)
return translation
flattened_translation = flatten_json(translation)
return flattened_translation
except json.JSONDecodeError as e:
raise ValueError(f"Error decoding JSON from file {filepath}: {e}")

Expand Down Expand Up @@ -170,7 +196,7 @@ def main():
"--directory",
type=str,
nargs="?",
default=os.path.join(os.getcwd(), "locales"),
default=os.path.join(os.getcwd(), "public/locales"),
help="Directory containing translation files(relative to the root directory).",
)
args = parser.parse_args()
Expand Down
Loading

0 comments on commit e143243

Please sign in to comment.