Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
translating every text layer
#7
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)
Reply


Messages In This Thread
translating every text layer - by jacques_duflos - 07-12-2023, 11:42 PM
RE: translating every text layer - by Ofnuts - 07-13-2023, 06:51 AM
RE: translating every text layer - by Ofnuts - 07-19-2023, 06:37 AM
RE: translating every text layer - by Ofnuts - 07-21-2023, 07:31 AM
RE: translating every text layer - by jacques_duflos - 07-25-2023, 03:44 AM
RE: translating every text layer - by Ofnuts - 07-25-2023, 06:23 AM
RE: translating every text layer - by ttt - 10-18-2024, 09:55 PM

Forum Jump: