diff --git a/i18nilize/src/internationalize/__pycache__/__init__.cpython-311.pyc b/i18nilize/src/internationalize/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..b889cd4 Binary files /dev/null and b/i18nilize/src/internationalize/__pycache__/__init__.cpython-311.pyc differ diff --git a/i18nilize/src/internationalize/__pycache__/generateFile.cpython-311.pyc b/i18nilize/src/internationalize/__pycache__/generateFile.cpython-311.pyc new file mode 100644 index 0000000..c96d7f1 Binary files /dev/null and b/i18nilize/src/internationalize/__pycache__/generateFile.cpython-311.pyc differ diff --git a/i18nilize/src/internationalize/__pycache__/generate_file.cpython-311.pyc b/i18nilize/src/internationalize/__pycache__/generate_file.cpython-311.pyc new file mode 100644 index 0000000..b2e53ec Binary files /dev/null and b/i18nilize/src/internationalize/__pycache__/generate_file.cpython-311.pyc differ diff --git a/i18nilize/src/internationalize/__pycache__/helpers.cpython-311.pyc b/i18nilize/src/internationalize/__pycache__/helpers.cpython-311.pyc new file mode 100644 index 0000000..38dda70 Binary files /dev/null and b/i18nilize/src/internationalize/__pycache__/helpers.cpython-311.pyc differ diff --git a/i18nilize/src/internationalize/helpers.py b/i18nilize/src/internationalize/helpers.py index b836004..adee5bc 100644 --- a/i18nilize/src/internationalize/helpers.py +++ b/i18nilize/src/internationalize/helpers.py @@ -25,6 +25,35 @@ 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): + with open("src/internationalize/jsonFile/translations.json", "w") as outfile: + outfile.write(json_object) + +# Input: None (for now) +# Output: None, but creates a local JSON file containing translations +def generate_file(): + file_content = { + "Token": "85124f79-0829-4b80-8b5c-d52700d86e46", + "translations" : [{ + "language": "French", + "hello": "bonjour", + "No": "Non", + "Why": "pourquoi", + }, + { + "language": "Spanish", + "hello": "Hola", + }, + ] + } + + # 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 = {} @@ -36,4 +65,5 @@ def make_translation_map(data): # get translations from hashmap given the language def get_translation(translations_map, language): - return translations_map.get(language, "Translation not found") \ No newline at end of file + return translations_map.get(language, "Translation not found") + diff --git a/i18nilize/src/internationalize/jsonFile/translations.json b/i18nilize/src/internationalize/jsonFile/translations.json new file mode 100644 index 0000000..9a4373a --- /dev/null +++ b/i18nilize/src/internationalize/jsonFile/translations.json @@ -0,0 +1,15 @@ +{ + "Token": "85124f79-0829-4b80-8b5c-d52700d86e46", + "translations": [ + { + "language": "French", + "hello": "bonjour", + "No": "Non", + "Why": "pourquoi" + }, + { + "language": "Spanish", + "hello": "Hola" + } + ] +} \ No newline at end of file diff --git a/i18nilize/tests/__pycache__/__init__.cpython-311.pyc b/i18nilize/tests/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..c610a01 Binary files /dev/null and b/i18nilize/tests/__pycache__/__init__.cpython-311.pyc differ diff --git a/i18nilize/tests/__pycache__/test_generate_file.cpython-311.pyc b/i18nilize/tests/__pycache__/test_generate_file.cpython-311.pyc new file mode 100644 index 0000000..5ccda6d Binary files /dev/null and b/i18nilize/tests/__pycache__/test_generate_file.cpython-311.pyc differ diff --git a/i18nilize/tests/test_generate_file.py b/i18nilize/tests/test_generate_file.py new file mode 100644 index 0000000..0ba59a7 --- /dev/null +++ b/i18nilize/tests/test_generate_file.py @@ -0,0 +1,29 @@ +import unittest +import json +from src.internationalize.generate_file import generate_file +from src.internationalize.helpers import get_json + +# run tests using python -m tests.test_generate_file at i18nilize directory level + +class TestGenerateFile(unittest.TestCase): + generate_file() + data = get_json("src/internationalize/jsonFile/translations.json") + + def test_token(self): + self.assertEqual(self.data['Token'], "85124f79-0829-4b80-8b5c-d52700d86e46") + + def test_translations(self): + translations = self.data['translations'] + self.assertEqual(len(translations), 2) + + # French + self.assertEqual(translations[0]['language'], "French") + self.assertEqual(translations[0]['hello'], "bonjour") + self.assertEqual(translations[0]['No'], "Non") + self.assertEqual(translations[0]['Why'], "pourquoi") + + # Spanish + self.assertEqual(translations[1]['language'], "Spanish") + self.assertEqual(translations[1]['hello'], "Hola") + +unittest.main() \ No newline at end of file