Python googletrans not work properly after long iteration

Viewed 119

I just tried to convert my JSON object fields data to my mother tongue (Sinhala). But sometimes it's not converted correctly. For example when I convert,

{ "artist_name": "Ajith Mutukumarana"}

sometimes it converted correctly as

{"artist_name":"අජිත් මුතුකුමාරණ"}

sometime its not converted correctly,

{ "artist_name": "Ajith Mutukumarana"}

It seems to be, with time and after long iteration, this issue is coming. My code is,

translator=Translator()

def convert_to_sinhala(text):     
  if(text==None):
        return None
  else:
        tra=translator.translate(text,dest="si").text 
        return tra


def format_song(song):
  obj = {
    "artist_name" :  convert_to_sinhala(song['artist_name'])
  }
  return obj
#my json object list with 1000 objects
for song in objects:
    
    obj = format_song(song) 
    print(obj)
    

Please suggest how can I solve this issue?

0 Answers
Related