Search code examples
javascriptgoogle-translateangular12google-translation-api

"Too many text segments" error in Google translate API


I am working in Angular-12. In our system, we are using "Google Translate" API.

So when we try to translate strings in bulk, then API returns the error

 {
  "error": {
    "code": 400,
    "message": "Too many text segments",
    "errors": [
      {
        "message": "Too many text segments",
        "domain": "global",
        "reason": "invalid"
      }
    ]
  }
}

This is the type of data we are sending in API,

API which we are using https://translation.googleapis.com/language/translate/v2?key=Alza.......

 {
        "source":"en",
        "target":"es",
        "q":["string1", "string1",......]
    }

Any kind of help is appritiable, thank you.


Solution

  • As mentioned in this documentation, the total number of strings (segments) that can be sent for translation per request is limited to 128. If the number of segments sent for translation exceeds 128, the error "Too many text segments" will be thrown by the API. Quoting the mentioned documentation:

    The maximum number of strings is 128.

    As an alternative, Cloud Translation Advanced can be used. It offers higher limits on the number of strings that can be sent for translation. Cloud Translation Advanced also provides support for glossaries, batch requests, and AutoML models. A comparison between the Basic and Advanced versions of the Translation API can be found here.