Giter Club home page Giter Club logo

Comments (6)

daniel-jones-deepl avatar daniel-jones-deepl commented on July 20, 2024

Hi @vf211, thanks for creating this issue.

Can you please provide a short example? I'm assuming you're using translate_text(), do you use tag_handling?.

from deepl-python.

vf211 avatar vf211 commented on July 20, 2024

Dear Daniel, thank you so much for your quick reply. Here is an example of text from the XML file where I have a problem:

1. Tap Set Up (1).

when it translates it replaces this with translated version but takes out the gap after "Tap", like this:

1. TapSet Up (1).

Here is the code I use. The issue is when we have bold text within the text element.

import lxml.etree as ET
import deepl

file='New_project_en-US_to_it-IT.xml' #starting file that needs a translate
file2='doc2.xml' # file that it will save to
lang='IT' #languate to translate to

tree = ET.parse(file)
root = tree.getroot()

translator = deepl.Translator("53f18f3b-ba9c-...") #API key from DEEPL API

for elem in root.iter():
try:
if elem.text:
elem.text = elem.text.replace(elem.text, translator.translate_text(elem.text, target_lang=lang).text)
if elem.tail:
elem.tail = elem.tail.replace(elem.tail, translator.translate_text(elem.tail, target_lang=lang).text)
except AttributeError:
pass
except deepl.DocumentTranslationException as error:
doc_id = error.document_handle.id
doc_key = error.document_handle.key
print(f"Error after uploading document ${error}, id: ${doc_id} key: ${doc_key}")
except deepl.DeepLException as error:
print(error)

tree.write(file2)

from deepl-python.

daniel-jones-deepl avatar daniel-jones-deepl commented on July 20, 2024

Hi @vf211, thanks for the reply. Please avoid exposing your authentication key in public; I've edited your post above. You should now regenerate your authentication key on your account page.

Your code looks okay.
In the line elem.text = elem.text.replace(elem.text, translator.translate_text(elem.text, target_lang=lang).text) could you share an example value of an elem.text passed to translate_text that contains the <b> elements you mentioned?
For example by adding print(elem.text) above that line.

I tried translating "Tap <b>Set Up</b> (1)" with target_lang="IT" but the result I get is "Tocca <b>Set Up</b> (1)" with a space correctly before the <b> tag.

from deepl-python.

vf211 avatar vf211 commented on July 20, 2024

Dear Daniel, thank you again for your reply.
Here is a snippet of text where the gap was also consumed in translation. This time in Lexiconlink tagging so il Raggi looks like ilRaggi.

Questo messaggio viene visualizzato quando un pacchetto raggiunge ilRaggi X rivelatore ma ilcodice a barre non viene letto.

Controllare quanto segue:

)

image

and this was the English that went into the code:

This message is displayed when a pack reaches the X-ray detector but the barcode is not read.

Check the following:

The alignment of the barcode scanner.

image

from deepl-python.

vf211 avatar vf211 commented on July 20, 2024

hi Daniel,

I added the xml tagging into the code as you suggested in your first email and that seems to have fixed our problems. Thank you so much for all your help!

from deepl-python.

daniel-jones-deepl avatar daniel-jones-deepl commented on July 20, 2024

Hi @vf211, great to hear that you have fixed the problems, thanks for the update!

from deepl-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.