40 lines
3.9 KiB
Python
Executable File
40 lines
3.9 KiB
Python
Executable File
from conversion.translation.translation_function import translate_comparison
|
|
import json, os
|
|
from openpyxl import Workbook
|
|
|
|
wb = Workbook()
|
|
ws = wb.active
|
|
testdata = [['Text', 'Source Language', 'Target Language', 'Outcome', 'Error']]
|
|
for data in testdata:
|
|
ws.append(data)
|
|
|
|
# languages_codes_json_file = open('/home/user/mnf/project/MNF/conversion/translation/language_codes.json')
|
|
# data_json2 = json.load(languages_codes_json_file)
|
|
data_json2 = {'Afrikaans': 'af', 'Albanian': 'sq', 'Amharic': 'am', 'Arabic': 'ar', 'Armenian': 'hy', 'Assamese': 'as', 'Aymara': 'ay', 'Azerbaijani': 'az', 'Bambara': 'bm', 'Basque': 'eu', 'Belarusian': 'be', 'Bengali': 'bn', 'Bhojpuri': 'bho', 'Bosnian': 'bs', 'Bulgarian': 'bg', 'Catalan': 'ca', 'Cebuano': 'ceb', 'Chichewa': 'ny', 'Chinese (Simplified)': 'zh-CN', 'Chinese (Traditional)': 'zh-TW', 'Corsican': 'co', 'Croatian': 'hr', 'Czech': 'cs', 'Danish': 'da', 'Divehi': 'dv', 'Dogri': 'doi', 'Dutch': 'nl', 'English': 'en', 'Esperanto': 'eo', 'Estonian': 'et', 'Ewe': 'ee', 'Filipino': 'tl', 'Finnish': 'fi', 'French': 'fr', 'Frisian': 'fy', 'Galician': 'gl', 'Ganda': 'lg', 'Georgian': 'ka', 'German': 'de', 'Greek': 'el', 'Guarani': 'gn', 'Gujarati': 'gu', 'Haitian Creole': 'ht', 'Hausa': 'ha', 'Hawaiian': 'haw', 'Hebrew': 'he', 'Hindi': 'hi', 'Hmong': 'hmn', 'Hungarian': 'hu', 'Icelandic': 'is', 'Igbo': 'ig', 'Iloko': 'ilo', 'Indonesian': 'id', 'Irish Gaelic': 'ga', 'Italian': 'it', 'Japanese': 'ja', 'Javanese': 'jv', 'Kannada': 'kn', 'Kazakh': 'kk', 'Khmer': 'km', 'Kinyarwanda': 'rw', 'Konkani': 'gom', 'Korean': 'ko', 'Krio': 'kri', 'Kurdish (Kurmanji)': 'ku', 'Kurdish (Sorani)': 'ckb', 'Kyrgyz': 'ky', 'Lao': 'lo', 'Latin': 'la', 'Latvian': 'lv', 'Lingala': 'ln', 'Lithuanian': 'lt', 'Luxembourgish': 'lb', 'Macedonian': 'mk', 'Maithili': 'mai', 'Malagasy': 'mg', 'Malay': 'ms', 'Malayalam': 'ml', 'Maltese': 'mt', 'Maori': 'mi', 'Marathi': 'mr', 'Meiteilon (Manipuri)': 'mni-Mtei', 'Mizo': 'lus', 'Mongolian': 'mn', 'Myanmar (Burmese)': 'my', 'Nepali': 'ne', 'Northern Sotho': 'nso', 'Norwegian': 'no', 'Odia (Oriya)': 'or', 'Oromo': 'om', 'Pashto': 'ps', 'Persian': 'fa', 'Polish': 'pl', 'Portuguese': 'pt', 'Punjabi': 'pa', 'Quechua': 'qu', 'Romanian': 'ro', 'Russian': 'ru', 'Samoan': 'sm', 'Sanskrit': 'sa', 'Scots Gaelic': 'gd', 'Serbian': 'sr', 'Sesotho': 'st', 'Shona': 'sn', 'Sindhi': 'sd', 'Sinhala': 'si', 'Slovak': 'sk', 'Slovenian': 'sl', 'Somali': 'so', 'Spanish': 'es', 'Sundanese': 'su', 'Swahili': 'sw', 'Swedish': 'sv', 'Tajik': 'tg', 'Tamil': 'ta', 'Tatar': 'tt', 'Telugu': 'te', 'Thai': 'th', 'Tigrinya': 'ti', 'Tsonga': 'ts', 'Turkish': 'tr', 'Turkmen': 'tk', 'Twi': 'ak', 'Ukrainian': 'uk', 'Urdu': 'ur', 'Uyghur': 'ug', 'Uzbek': 'uz', 'Vietnamese': 'vi', 'Welsh': 'cy', 'Xhosa': 'xh', 'Yiddish': 'yi', 'Yoruba': 'yo', 'Zulu': 'zu'}
|
|
|
|
original_text = "my name is dharmesh"
|
|
text = original_text
|
|
def test_run():
|
|
languages = list(data_json2.keys())
|
|
for source_lang in languages:
|
|
if not source_lang == "English":
|
|
text = translate_comparison(original_text, "en", data_json2[str(source_lang)])
|
|
for target_lang in languages:
|
|
try:
|
|
translated_text = translate_comparison(text, data_json2[str(source_lang)], data_json2[str(target_lang)])
|
|
testdata = [[str(text), str(source_lang), str(target_lang), translated_text , 'PASS', 'NOTHING']]
|
|
for data in testdata:
|
|
ws.append(data)
|
|
wb.save("/home/user/mnf/project/MNF/media/file_11.xlsx")
|
|
except Exception as e:
|
|
testdata = [[str(text), str(source_lang), str(target_lang), translated_text , 'FAIL', str(e)]]
|
|
for data in testdata:
|
|
ws.append(data)
|
|
wb.save("/home/user/mnf/project/MNF/media/file_11.xlsx")
|
|
# break
|
|
|
|
# wb.save("file_" + str(script) + ".xlsx")
|
|
return True
|
|
|
|
|