Skip to content

Translations

Where can drag&bot translations be used?

Translations can be used for the following fields

Function Blocks

  • title
  • description

Parameters

  • displayTitle
  • description
  • availableOptions

Constraints

  • msg

How do drag&bot translations work

When displaying a Function Block or Parameter drag&bot will check if translations for the Strings in the previously mentioned fields are provided on the same level.

{
    "availableOptions": [
        "Cat",
        "Dog",
        "Horse"
    ],
    "paramId": "b78a25e9-e276-528e-158f-ee3fbe87b591",
    "displayTitle": "Animal",
    "title": "animal",
    "description": "Select an animal from the given options",
    "value": null,
    "type": "select",
    "parameters": [],
    "dataType": "string",
    "reference": null,
    "constraints": []
}

In this example the possible strings to translate would be:

  • "Animal"
  • "Cat"
  • "Dog"
  • "Horse"
  • "Select an animal from the given options"

How to provide translation data

Translation fields field require to have the following structure.

"translations": [
    {
        "language": "<language>",
        "values": [
            {
                "key": "<key>",
                "translation": "<translation>"

            }
        ]
    }
]
The placeholders , and need to be replaced by the corresponding values.

the short code of the language the translation is for. (see Supported Languages) The key of the translation. The key is what is initialy used in the Functions Block or Parameters field and will be replaced by it's translation. The key has to match the entire string of a field. If the key matches on a part of a string the translation won't be used. The translation use when displaying in the certain language.

Applying this to the above animal example would result in the following parameter.

{
    "availableOptions": [
        "Cat",
        "Dog",
        "Horse"
    ],
    "paramId": "b78a25e9-e276-528e-158f-ee3fbe87b591",
    "displayTitle": "Animal",
    "title": "animal",
    "description": "Select an animal from the given options",
    "value": null,
    "type": "select",
    "parameters": [],
    "dataType": "string",
    "reference": null,
    "constraints": [],
    "translations": [
        {
            "language": "de",
            "values": [
                {
                    "key": "Animal",
                    "translation": "Tier"
                },
                {
                    "key": "Cat",
                    "translation": "Katze"
                },
                {
                    "key": "Dog",
                    "translation": "Hund"
                },
                {
                    "key": "Horse",
                    "translation": "Pferd"
                },
                {
                    "key": "Select an animal from the given options",
                    "translation": "Wählen Sie ein Tier aus den gegebenen Optionen"
                }
            ]
        }
    ]
}

Explaining the changes

...
        {
            "language": "de",
            "values":  [
...
All the translation values in this object will only be used when German ("de") is selected.

...
        "values": [
            {
                "key": "Animal",
                "translation": "Tier",
            },
...
"Animal" will be replaced with "Tier".

Supported Languages

  • "en" (English)
  • "de" (German)

Example

This Example Function Block uses the Parameter from above and Translations for the Function Block fields title and description.

{
    "version": "1.0.0",
    "errorcodes": [],
    "skip": false,
    "type": "Basic",
    "title": "Translation Example",
    "description": "Example Function Block to show how to use translations.",
    "image": "dnb-icon-general_skill",
    "script": "#!/usr/bin/env python\n\n# optional IMPORTS\n# e.g import rospy\n\ndef execute(input_parameters, output_parameters):\n\t# RUNS ON BLOCK EXECUTION\n\t# do actions with hardware, software\n\t# produce outputs\n\treturn output_parameters\n\n#def abort():\n\t# RUNS ON MANUAL ABORT OR AFTER ERROR\n\t# stop pending actions, clean up resources\n\t#pass",
    "identifier": "33b492d5-f996-4d53-8d8a-cf24d0b59712",
    "inputParameters": [
        {
            "availableOptions": [
                "Cat",
                "Dog",
                "Horse"
            ],
            "paramId": "b78a25e9-e276-528e-158f-ee3fbe87b591",
            "displayTitle": "Animal",
            "title": "animal",
            "description": "Select an animal from the given options",
            "value": null,
            "type": "select",
            "parameters": [],
            "dataType": "string",
            "reference": null,
            "constraints": [],
            "translations": [
                {
                    "language": "de",
                    "values": [
                        {
                            "key": "Animal",
                            "translation": "Tier"
                        },
                        {
                            "key": "Cat",
                            "translation": "Katze"
                        },
                        {
                            "key": "Dog",
                            "translation": "Hund"
                        },
                        {
                            "key": "Horse",
                            "translation": "Pferd"
                        },
                        {
                            "key": "Select an animal from the given options",
                            "translation": "Wählen Sie ein Tier aus den gegebenen Optionen"
                        }
                    ]
                }
            ]
        }
    ],
    "outputParameters": [],
    "globalParameters": [],
    "translations": [
        {
            "language": "de",
            "values": [
                {
                    "key": "Translation Example",
                    "translation": "Übersetzung-Beispiel"
                },
                {
                    "key": "Example Function Block to show how to use translations.",
                    "translation": "Beispiel-Funktionsblock zur Veranschaulichung der Verwendung von Übersetzungen."
                }
            ]
        }
    ],
    "models": [],
    "format": "linked#2.4.0"
}

Download Example