Languages supported by Cucumber-JVM

Filed under: Cucumber, — Tags: Gherkin — Thomas Sundberg — 2018-01-24

Cucumber-JVM supports a lot of languages for writing concrete examples that describes a wanted behaviour. The examples are written in feature files. The five important keywords are:

These keywords are translated into many different languages. So many that it may be hard to keep track of them. How do you find the keywords for your native language? Luckily, cucumber can help with that using its built in help system.

How do you print the help?

If you run a regular command line program, getting help is often a matter of passing the argument -H to a command line tool. When I do that for cp, it looks like this:

$ cp -H
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file target_file
       cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file ... target_directory

I get brief usage instructions.

How can I do that with Cucumber if I'm using Maven to build my project? The answer is, pass a Cucumber option to Cucumber.

It may look like this: mvn test -Dcucumber.options="--help"

This will run the Maven test target and pass the option --help to Cucumber. Somewhere in the build output I found this:

Running RunCukesTest
Usage: java cucumber.api.cli.Main [options] [[[FILE|DIR][:LINE[:LINE]*] ]+ | @FILE ]

Options:

  -g, --glue PATH                        Where glue code (step definitions, hooks
                                         and plugins) are loaded from.
  -p, --[add-]plugin PLUGIN[:PATH_OR_URL]
                                         Register a plugin.
                                         Built-in formatter PLUGIN types: junit,
                                         html, pretty, progress, json, usage, rerun,
                                         testng. Built-in summary PLUGIN types:
                                         default_summary, null_summary. PLUGIN can
                                         also be a fully qualified class name, allowing
                                         registration of 3rd party plugins.
                                         --add-plugin does not clobber plugins of that
                                         type defined from a different source.
  -f, --format FORMAT[:PATH_OR_URL]      Deprecated. Use --plugin instead.
  -t, --tags TAG_EXPRESSION              Only run scenarios tagged with tags matching
                                         TAG_EXPRESSION.
  -n, --name REGEXP                      Only run scenarios whose names match REGEXP.
  -d, --[no-]-dry-run                    Skip execution of glue code.
  -m, --[no-]-monochrome                 Don't colour terminal output.
  -s, --[no-]-strict                     Treat undefined and pending steps as errors.
      --snippets [underscore|camelcase]  Naming convention for generated snippets.
                                         Defaults to underscore.
  -v, --version                          Print version.
  -h, --help                             You're looking at it.
  --i18n LANG                            List keywords for in a particular language
                                         Run with "--i18n help" to see all languages
  --junit,OPTION[,OPTION]*               Pass the OPTION(s) to the JUnit module.
                                         Use --junit,-h or --junit,--help to print the
                                         options of the JUnit module.

Feature path examples:
                                   Load the files with the extension ".feature"
                                         for the directory 
                                         and its sub directories.
  /.feature                  Load the feature file /.feature
                                         from the file system.
  classpath:/.feature        Load the feature file /.feature
                                         from the classpath.
  /.feature:3:9              Load the scenarios on line 3 and line 9 in
                                         the file /.feature.
  @/                         Parse / for feature paths generated
                                         by the rerun formatter.

This is a lot of information, but you can see that if you pass the option --i18n LANG you will get the translations for your language of choice. All you have to do now is substitute LANG with your language code.

If you are uncertain of the language code to use, it is possible to ask for all supported language codes by passing the argument --i18n help.

mvn test -Dcucumber.options="--i18n help" gives you this list:

Running RunCukesTest
af
am
ar
ast
az
bg
bm
bs
ca
cs
cy-GB
da
de
el
em
en
en-Scouse
en-au
en-lol
en-old
en-pirate
eo
es
et
fa
fi
fr
ga
gj
gl
he
hi
hr
ht
hu
id
is
it
ja
jv
ka
kn
ko
lt
lu
lv
mk-Cyrl
mk-Latn
mn
nl
no
pa
pl
pt
ro
ru
sk
sl
sr-Cyrl
sr-Latn
sv
ta
th
tl
tlh
tr
tt
uk
ur
uz
vi
zh-CN

That's a lot of languages! I counted to 72. With this list, you have to locate your native language. As I'm from Sweden I located my language code to be sv. Listing the Gherkin keywords in swedish is now a matter of passing the option -i18n sv.

mvn test -Dcucumber.options="--i18n sv" gave me these translations:

Running RunCukesTest
      | feature          | "Egenskap"                          |
      | background       | "Bakgrund"                          |
      | scenario         | "Scenario"                          |
      | scenario outline | "Abstrakt Scenario", "Scenariomall" |
      | examples         | "Exempel"                           |
      | given            | "* ", "Givet "                      |
      | when             | "* ", "När "                        |
      | then             | "* ", "Så "                         |
      | and              | "* ", "Och "                        |
      | but              | "* ", "Men "                        |
      | given (code)     | "Givet"                             |
      | when (code)      | "När"                               |
      | then (code)      | "Så"                                |
      | and (code)       | "Och"                               |
      | but (code)       | "Men"                               |

This gives me all the translations I need. Apart from translations of, given, when, then, etc. I get translations for the annotations needed for connecting the steps in my Java code.

The only thing I'm currently missing is the name of the language in the language list. Including that in the output would make it easier to find the language you are looking for. I guess if I want it, I need to support the open source project and add it myself.

Acknowledgements

I would like to thank Malin Ekholm for proofreading and helping me to find my typos.

Resources



(less...)

Pages

About
Events
Why

Categories

Agile
Automation
BDD
Clean code
Continuous delivery
Continuous deployment
Continuous integration
Cucumber
Culture
Design
DevOps
Executable specification
Git
Gradle
Guice
J2EE
JUnit
Java
Javascript
Kubernetes
Linux
Load testing
Maven
Mockito
New developers
Pair programming
PicoContainer
Presentation
Programming
Public speaking
Quality
React
Recruiting
Requirements
Scala
Selenium
Software craftsmanship
Software development
Spring
TDD
Teaching
Technical debt
Test automation
Tools
Web
Windows
eXtreme Programming

Authors

Thomas Sundberg
Adrian Bolboaca

Archives

Meta

rss RSS