07-25-2023, 03:44 AM
Im not sure I got it right. The function gimp_text_layer_get_text will return a uft-8 text, and it's better to decode it before using it with the function translator.translate(text) ? According to its documentation, the translator function returns a unicode text. Should I re-code it in uft-8 before using the gimp_text_layer_set_text function ? the code for getting the text, translate it and update the layer's text would look like this :
Code:
# Récupérer le contenu texte du calque dupliqué
text = pdb.gimp_text_layer_get_text(duplicate)
if text is None :
print ("----------text had markup-------------")
text = pdb.gimp_text_layer_get_markup(duplicate)
# quitter les markups avec une RegEx
text= re.sub(r"<.*?>", "", text)
# essayer de traduir
try:
text = text.decode("uft-8")
translated_text = translator.translate(text).encode("uft-8")
except Exception as e:
translated_text = "Erreur lors de la traduction : {}".format(e)
# Mettre à jour le texte du calque dupliqué avec la traduction
pdb.gimp_text_layer_set_text(duplicate, translated_text)