Search code examples
chatgpt-api

How can I translate _multiple_ strings at once?


I'm researching an idea of translating html page from one language to another -- to translate visible text, if be more specific. I already split html to markup and text chunks, and now I need to translate text by ChatGPT. But for my idea I need to translate N pieces of text strictly to N pieces. Currently my best experiments:

"Translate to English this N lines line by line: ["line1","line2",...,"lineN"]"

But for some widely use phrases ChatGPT can't resist the temptation to join two strings into one. For example, it will join phrases "If you don't want to receive this emails click this", "link" with high probability. Of cause, in my case any mismatch between number of texts and number of translations is fatal.

Is there any method to force ChatGPT to transform N strings to N strings?


Solution

  • Looks like I found appropriate query:

    Translate this N strings to <language> preserving its number: [ 1. "Line1", 2. "Line2", ... , N. "LineN"]
    

    It produces stable output like:

    1. "Translation1"
    2. "Translation2"
    ...
    N. "TranslationN"