Temporary removal of HTML from string for Google Translate API to reduce cost

后端 未结 1 624
死守一世寂寞
死守一世寂寞 2021-01-21 11:56

I have to translate some details using a Google API which we\'re paying for. The details contain HTML, and Google charges for each character. I don\'t want to send the complete

1条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-21 12:38

    Haha, I also had that problem. But it has been while ago...

    I think, there was a problem were - due to translation-nature - some sentenceparts were swaped. So I was not able to fit the tags in at the same position, first. But I think there was a way to get some metadata from the translationprocess, were you can see which part of the sentence have moved to a new position and what the content was... I know, I solved it finally. But I cant recall how :(

    If every word takes the same place again after translation, you could first separate all words by whitespace OR htmltag into an array and remember where each HTML-tag was and reapply that after translation...

    0 讨论(0)
提交回复
热议问题