import re
from deep_translator import GoogleTranslator
fname = input('Enter file name: ')
if (len(fname) < 1): fname = 'text.po'
fh = open(fname, 'r+')
translated=list()
for line in fh:
if not line.startswith('msgid '):
continue
piece=re.findall('"(.*)"', line)
texte = GoogleTranslator(source='auto', target='french').translate(piece[0])
translated.append(texte)
print(translated)
for line in fh:
i =+ 0
if not line.startswith('msgstr '):
continue
piece2=re.findall('"()"', line)
for space in piece2:
fh.write(line.replace(space, translated[i] ))
fh.close()
msgid "Something goes here"
msgstr "nothing here"
extract "something goes here" which I translate and put back into the "nothing here"
purpose
parse texte value in piece2
text.po file
- msgid "i'm Joe"
- msgstr ""
desired output
- msgid "i'm Joe"
- msgstr "Je suis Joe"
replace function not working. how to fix it please