cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

API Translate: How to use double quotes ?

if for example I need to translate this text :

 

this is the "as is system" text

 

The API return an error if I try to use escaped double quotes. And the API don't accept markups (I have tried to substitute double quotes with the markup but I receive an error message)

The only solution I have found is to remove double quotes from the text

 

Any idea ?

Message 1 of 6
latest reply
5 REPLIES 5

Re: API Translate: How to use double quotes ?

Specifics on what language/api/tools and what field you are trying to get working would help as this is kind of contextual to those things.

Message 2 of 6
latest reply

Re: API Translate: How to use double quotes ?

I use api translate and the issue appears if the text to be translate contains double quotes

commerce/translation/v1_beta/translate

 

This appears in every language from an to

Message 3 of 6
latest reply

Re: API Translate: How to use double quotes ?

My apologies, I forgot about the Translate API.

 

Still likely language specific, have you tried double escaping?

 

in python I get the response of:

 

b'{"from":"en","to":"es","translations":[{"originalText":"hello this \\"is an\\" item","translatedText":"hola este art\xc3\xadculo \\"\\"es un\\"\\""}]}'

 

for a payload of:

 

python code:

json = {
"from" : "en",
"text" : [
"hello this \"is an\" item"
],
"to" : "es",
"translationContext" : "ITEM_DESCRIPTION"
}

 

Same result if I use ITEM_TITLE as well.

 

 

Message 4 of 6
latest reply

Re: API Translate: How to use double quotes ?

Additional note: without quotes I am getting 2 different results for ITEM_TITLE and ITEM_DESCRIPTION:

 

ITEM_TITLE

b'{"from":"en","to":"es","translations":[{"originalText":"hello this is an item","translatedText":"hola this is a item"}]}'

 

ITEM_DESCRIPTION

b'{"from":"en","to":"es","translations":[{"originalText":"hello this is an item","translatedText":"hola este es un art\xc3\xadculo"}]}

 

It is a beta and I don't see any in depth detailed documented guidelines on how it is intended to be used, but note that "text" : [ ] is an array of strings. -- It appears when using ITEM_TITLE that whatever systems the server is using splits the string and operates only on the first element (strings are arrays, different languages handle things differently, this is a common python issue when you don't use a trailing comma on a set, but json forbids trailing commas, so you end up with potentially unexpected behavior if that isn't accounted for).

 

You will likely have to play with it a bit to get the behavior you want.

Message 5 of 6
latest reply

Re: API Translate: How to use double quotes ?

To clarify language specific, i mean programming language.

Message 6 of 6
latest reply