Translate¶
Translate Robot Framework source files from one or many languages to different one.
Note
Required Robot Framework version: >=6.0
Enabling the formatter
Translate is not included in default formatters, that’s why you need to call it with --select
explicitly:
robocop format --select Translate
Or configure enabled
parameter:
robocop format --configure Translate.enabled=True
Example of Robot Framework markers translation:
*** Settings ***
Documentation Dokumentacja zestawu
Library Collections
Variables vars.py
*** Test Cases ***
Pierwszy test
[Setup] Setup Keyword
Step 1
*** Ustawienia ***
Documentation Dokumentacja zestawu
Biblioteka Collections
Zmienne vars.py
*** Przypadki Testowe ***
Pierwszy test
[Inicjalizacja] Setup Keyword
Step 1
The language can be configured using language
parameter with the language code (default en
- English):
robocop format -c Translate.enabled=True -c Translate.language=se
Since the translation is from one or many languages to one, only one language can be configured.
Source language¶
Robocop will translate only markers that can be recognized. If your source file is written in different language you need to configure Robocop to recognize given language. See Language support for more details. Following example configure Robocop to read English, Polish and German languages and translate Robot Framework markers to Ukrainian:
robocop format -c Translate.enabled=True -c Translate.language=uk --language pl,de source_in_pl_and_de.robot
BDD keywords¶
BDD keywords are not translated by default. Set translate_bdd
parameter to True
to enable it:
robocop format -c Translate.enabled=True -c Translate.translate_bdd=True files/
*** Test Cases ***
Test with BDD keywords
Given login page is open
When valid username and password are inserted
And credentials are submitted
Then welcome page should be open
*** Testfälle ***
Test with BDD keywords
Angenommen login page is open
Wenn valid username and password are inserted
Und credentials are submitted
Dann welcome page should be open
Some language have more than one alternative to BDD keyword. For example Polish can use “Kiedy” or “Gdy” when
translating “When” keyword. In this situation Robocop will chose the first one (sorted alphabetically). It can
be overwritten using <bdd_keyword>_alternative
parameters:
robocop format -c Translateenabled=True -c Translate.language=pl -c Translate.translate_bdd=True -c Translate.when_alternative=Gdy files/
Language headers¶
Robocop can add or replace existing language header in the files. For example, if you’re translating file
written in German to Swedish, the language header will change from language: de
to language: se
.
Translation to English will remove language header since it’s not necessary.
To do this configure add_language_header
parameter to True
:
robocop format -c Translate.enabled=True -c Translate.add_language_header=True files/
# language: de
*** Testfälle ***
Test
Step
# language: se
*** Testfall ***
Test
Step
*** Test Cases ***
Test
Step