how to translate a JSON

Asked

Viewed 2,086 times

0

I have a JSON here with 1000 objects inside an array, ta in English, the problem and I want to translate to pt-Br and when I use google translator simply Buga, for example

{ "Description": "Do you like donuts? If you’re also a donuts Lover, come on and Enjoy it!" }, { "Description": "(second ex aleatorio in English...)" } ... + 1000

In some lines the descriptions remain in English in others not even going through google translator, there is another way to translate? Because I need the en-Br descriptions, to pull the data inside a loop list listing all the descriptions, so I need the item name Description remains to give item.Description and list them all, there is another way more functional?

vuejs use

  • In this case, you will need a translator who accepts the JSON format. Whether online, or API, for example the Deepl. Remembering that is paid. Although it is cheap, you pay an additional amount depending on the amount of translated characters. Or who knows to API Translation from Google that can be much cheaper.

  • Is an array with Description only? You can use a regex to extract only the sentences to a text file, translate, then another regex to re-mount JSON. This assuming that the translation problem is by format, not by phrases.

  • and a single array with 1000 objects inside, each one has a description, to see here regex seems to solve but I have to put 500 objects at a time pq otherwise weighs too much and falls the regex, to see here I can select in the regex { "Description":"counteudo"} putting = (?:"Description":")(.*?)(?:") but I just want to select the content without quotation marks as I do ?

  • If you are using Javascript and receive a JSON, no need to use regex. Javascript itself has the method JSON.parse which transforms the string containing JSON into arrays and objects of the language itself, that make it much easier to manipulate this data (just one for in the object array, accessing each one’s Description). And tb has the method JSON.stringify which turns back to a string containing all the JSON. Using regex is to complicate randomly...

  • But if you really want to use regex - which again, I don’t recommend, use Javascript and be happy :-) - you can use something like "description"\s*:\s*"([^"]*)", which can work for most cases (see). The problem is that it may have escaped quotes in the string (\"), there the regex gets a lot more complicated. Again, it’s not worth using regex, especially when Javascript already has natively more suitable tools to handle JSON :-)

  • I tried to do so, gave a v-for in a li accessing the Description of each item, thus <li v-for="item in json"> {{ item.Description }} </li> (returns the 1000 raw descriptions in text), concatenating with html [{"Description":"{{ item.Description }}"] creating an array of description objtos directly in the problem browser and that qnd do this google translator he creates quotes in the descriptions bugando the json, I will try to learn to translate and goes through the JSON.stringify

  • https://www.logisticinfotech.com/translate-language-files-online-json/

Show 2 more comments

1 answer

0


Solved using https://www.logisticinfotech.com/translate-language-files-online-json/

Tbm has another way that is to extract with regex and join the parts as the friend above said but more mt more laborious since the json has objects with several items, da para juntar com json Decode/Encode e array merge, the above translation reaches the level google translator and respects the json training, the structure stays intact and validates different from google.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.