fluttergoogle-translategoogle-translation-apiflutter-localizationsgoogle-translate-api

Prevent Google Translate from translating a variable


I see Google Translate, both the web interface and API translates a variable like '{userName}'. Is there a way to preserve the variable as it is?

enter image description here

Context: I have a Flutter project with localization support. The ARB file contains an entry like below. Because Google translate translates the {userName} part (to Spanish in this example), the Spanish version of the app breaks.

  "greetingMorningWithName": "Good morning, {userName}!",
  "@greetingMorningWithName": {
    "description": "A message with a single parameter",
    "placeholders": {
      "userName": {
        "type": "String",
        "example": "Bob"
      }
    }
  },

Note: If I change the variable name from 'userName' to 'user_Name', it's not translated, but I'd like to avoid it as I want to stick to the camel case convention.


Solution

  • The ARB file is not supported nor trained by the Translation API.  These are the supported formatted files only:    

    enter image description here

    Plain text and HTML are also trained in the translation models.  

    You can create a Glossary to have your syntax {userName} to not be translated and have your customized dictionary. Another workaround is to create a Custom Model where you can train a model in ARB file format.