Skip to content

Commit

Permalink
Merge branch 'main' into fileGeneration
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewahn-ubc authored Oct 25, 2024
2 parents 228d851 + 5afe843 commit 1d8ba87
Show file tree
Hide file tree
Showing 26 changed files with 533 additions and 3 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Django CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.12]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
cd core
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Django Tests
run: |
cd core
python manage.py test
- name: Run PIP Tests
run: |
cd i18nilize
python3 -m tests.test_read_file
python3 -m tests.test_parse_json
6 changes: 6 additions & 0 deletions core/i18nilize/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ class Token(models.Model):

def __str__(self):
return str(self.value)

class Translation(models.Model):
token = models.ForeignKey(Token, on_delete=models.CASCADE)
original_word = models.CharField(max_length = 255)
translated_word = models.CharField(max_length = 255)
language = models.CharField(max_length = 255)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
31 changes: 29 additions & 2 deletions i18nilize/src/internationalize/helpers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import json

# Function to parse json file, given its path
def get_json(file_path):
with open(file_path, 'r') as file:
data = json.load(file)
try:
# open file and parse
with open(file_path, 'r') as file:
data = json.load(file)
except FileNotFoundError:
print("File not found")
raise FileNotFoundError
except json.JSONDecodeError as e:
print("JSON Decoding Error")
raise e
except Exception as e:
print(f"Error: {e}")
raise e
return data

# Input:
Expand All @@ -13,6 +25,7 @@ def get_token(file_path):
token = data["Token"]
return token


# Input: a JSON object
# Output: None, but creates a local JSON file containing the object
def create_json(json_object):
Expand Down Expand Up @@ -40,3 +53,17 @@ def generate_file():
# transforms the dictionary object above into a JSON object
json_object = json.dumps(file_content, indent=4)
create_json(json_object)

# make hashmap from translations
def make_translation_map(data):
translations_map = {}
for translation in data.get('translations', []):
language = translation.get('language')
if language:
translations_map[language] = translation
return translations_map

# get translations from hashmap given the language
def get_translation(translations_map, language):
return translations_map.get(language, "Translation not found")

Binary file added i18nilize/tests/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file added i18nilize/tests/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file added i18nilize/tests/__pycache__/test.cpython-310.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions i18nilize/tests/resources/test_invalid_json.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"asdaiosdjhioashd

asdiu

ashdi
14 changes: 14 additions & 0 deletions i18nilize/tests/resources/test_json.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Token": "85124f79-0829-4b80-8b5c-d52700d86e46",
"translations" : [{
"language": "French",
"hello": "bonjour",
"No": "Non",
"Why": "pourquoi"
},
{
"language": "Spanish",
"hello": "Hola"
}
]
}
Loading

0 comments on commit 1d8ba87

Please sign in to comment.