Comments (6)
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.
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.
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.
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:
)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.from deepl-python.
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.
Hi @vf211, great to hear that you have fixed the problems, thanks for the update!
from deepl-python.
Related Issues (20)
- [Bug] DeepL Write adds sentences describing chosen style
- DeepL documentation states ZH is supported as target for translate_docs but on execution it errors HOT 2
- translate_document_from_filepath fails to recognise XML files HOT 1
- Error: Bad request, message: Document is empty HOT 4
- [Feature Request] Make auto-retry toggleable HOT 3
- can't use my auth key, and can't sign up to the API plan for free trial HOT 4
- preserve_formatting missing in translate_document() function HOT 5
- In the translation result, the "left" quotation mark is missing. HOT 1
- Convenient request max retries setup HOT 4
- Encoding problem when translating to french. HOT 2
- New feature : customize timeout duration HOT 2
- Glossaries HOT 1
- deepl.Formality.MORE results in untranslated text HOT 1
- Mismatch in the placement of ignore tags and lack of translation HOT 1
- The deepl.Formality is ignored
- Abnormal strings in translation results: ãã£ã£ãç§ã¡ã¡åã HOT 5
- `translate_document()` should `seek(0, 0)` the output file after being done
- Disambiguate homonyms in glossaries / provide alternative translations? HOT 3
- When translating long English fields into Chinese, the last paragraph was lost
- Glossary flexible search
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deepl-python.