from conversion.translation.twostepconversion import translate_function import json,os from pymongo import MongoClient from openpyxl import Workbook # from .detection import getInputs from .translation_function import translate_comparison from .final_transliteration_only import transliterate wb = Workbook() ws = wb.active testdata = [['text','src_lang','dest_lang','src_script','dest_script','Outcome', "Error","translation"]] for data in testdata: ws.append(data) client = MongoClient('mongodb+srv://mynextfilm:mnf123@cluster0.ojasb.mongodb.net/myFirstDatabase?retryWrites=true&w=majority') db = client.DB languages_json_file = open('/home/user/mnf/project/MNF/conversion/translation/lls.json') data_json = json.load(languages_json_file) languages_condes_json_file = open('/home/user/mnf/project/MNF/conversion/translation/lls2.json') data_json2 = dict(json.load(languages_condes_json_file)) languages_transliteration_json_file = open('/home/user/mnf/project/MNF/conversion/translation/scripts.json') data_json3 = json.load(languages_transliteration_json_file) option3 = "Yes" option4 = "Yes" option5 = "Yes" option6 = "Yes" restrict_to_five = "yes" dual_dial_script = "No" def test_run(): texts = [["This is an English Statement", "en", "Latin"]] # script_ids = ["scr_001"] for scripti in texts: # user_script_data = db["mnfapp_mnfscriptdatabase"].find_one({"script_id": script_id}) #for now hard-coding but should be dynamic # dial_src_lang = "en" # non_dial_src_lang = "en" # dial_src_script = "Latin" # allow_translations = 0 text = scripti[0] src_lang = scripti[1] src_script = scripti[2] # non_dial_src_lang = scripti[2] # action_line_src_script = scripti[4] for i in data_json: if i['codeSrc'] == src_lang: lang_list = i['options'] # if i['codeSrc'] == non_dial_src_lang: # non_dial_dest_lang_list = i['options'] for iii in lang_list: for ioi in data_json: if str(ioi['key']) == str(iii): dest_lang = ioi['codeSrc'] # for ii in data_json: # if str(ii['key']) == str(i): # dest_lang = ii['codeSrc'] # if str(ii['key']) == str(j): # dial_dest_lang = ii['codeSrc'] # if dial_dest_lang == "pa": # allow_translations = 1 # for i in data_json2: # if i == # print("********************---------------------777777799999999---------***************************") # print(data_json2['Hindi']) try: src_script = data_json2[str(iii)] except: src_script = "Latin" for i in data_json3: if i['key'] == src_script: scripts = i['options'] for script_to_be_transliterated_in in scripts: dest_script = str(script_to_be_transliterated_in) # user_script_data["nondial_dest_language"] = str(non_dial_dest_lang) # user_script_data["dial_dest_language"] = str(dial_dest_lang) # user_script_data["dual_dial_script"] = str(dual_dial_script) # user_script_data["dial_dest_script"] = str(dial_dest_script) # user_script_data["nondial_src_script"] = str(action_line_src_script) # db["mnfapp_mnfscriptdatabase"].save(user_script_data) print("11 Entering Function") translation = "NO" try: # if allow_translations == 1: # filename = translate_function( # script, # script_id, # dial_src_lang, # non_dial_src_lang, # dial_src_script, # restrict_to_five, # option3, # option4, # option5, # option6, # ) trans_text=translate_comparison(text, src_lang, str(dest_lang)) translation = "DONE" transs_text = transliterate(dest_script, src_script, src_lang, trans_text) testdata = [[str(text), str(src_lang), str(dest_lang), str(src_script), str(script_to_be_transliterated_in),'PASS', "NOTHING", translation]] print("11 Saving here") for data in testdata: ws.append(data) wb.save("file_1122.xlsx") # db["mnfapp_mnfscriptdatabase"].save(user_script_data) # if os.path.exists("/home/user/mnf/project/MNF/media/"+str(user_script_data['translated_script_path'])): # os.remove("/home/user/mnf/project/MNF/media/"+str(user_script_data['translated_script_path'])) except Exception as e: print("11 Some Error Encountered") testdata = [[str(text), str(src_lang), str(dest_lang), str(src_script), str(script_to_be_transliterated_in), 'FAIL', str(e), translation]] for data in testdata: ws.append(data) wb.save("file_1122.xlsx") wb.save("file_" + str(script) + ".xlsx") return True # filename = translate_function( # script_file_path, # script_id, # dial_src_lang, # non_dial_src_lang, # dial_src_script, # restrict_to_five, # option3, # option4, # option5, # option6, # )