Gherkin parser and compiler for Java providing complete parsing of Gherkin feature files into AST and executable Pickles for BDD testing frameworks
—
Gherkin supports internationalization through language dialects, allowing feature files to be written in many different languages. The language support system provides keyword translation and locale-specific parsing rules.
The GherkinDialectProvider manages language dialects and provides access to language-specific keywords.
/**
* Create a dialect provider with English as default language
*/
public GherkinDialectProvider();
/**
* Create a dialect provider with custom default language
* @param defaultDialectName language code for default dialect (e.g., "en", "fr", "de")
*/
public GherkinDialectProvider(String defaultDialectName);
/**
* Get the default language dialect
* @return GherkinDialect for the default language
* @throws ParserException.NoSuchLanguageException if default language not found
*/
public GherkinDialect getDefaultDialect();
/**
* Get dialect for specific language
* @param language language code (e.g., "en", "fr", "de", "es")
* @return Optional containing dialect if language is supported
*/
public Optional<GherkinDialect> getDialect(String language);
/**
* Get all available language codes
* @return Set of supported language codes
*/
public Set<String> getLanguages();Usage Examples:
// Use default English dialect
GherkinDialectProvider provider = new GherkinDialectProvider();
GherkinDialect english = provider.getDefaultDialect();
// Use French as default
GherkinDialectProvider frenchProvider = new GherkinDialectProvider("fr");
GherkinDialect french = frenchProvider.getDefaultDialect();
// Check available languages
Set<String> languages = provider.getLanguages();
System.out.println("Supported languages: " + languages);
// Output: [en, fr, de, es, it, pt, ru, zh-CN, ja, ...]
// Get specific language dialect
Optional<GherkinDialect> spanish = provider.getDialect("es");
if (spanish.isPresent()) {
System.out.println("Spanish feature keywords: " +
spanish.get().getFeatureKeywords());
// Output: [Característica, Funcionalidad]
}GherkinDialect provides access to language-specific keywords and metadata for a particular language.
/**
* Get language code
* @return language code (e.g., "en", "fr", "de")
*/
public String getLanguage();
/**
* Get English name of the language
* @return English language name (e.g., "English", "French", "German")
*/
public String getName();
/**
* Get native name of the language
* @return native language name (e.g., "English", "Français", "Deutsch")
*/
public String getNativeName();
/**
* Get Feature keywords for this language
* @return List of translated "Feature" keywords
*/
public List<String> getFeatureKeywords();
/**
* Get Rule keywords for this language
* @return List of translated "Rule" keywords
*/
public List<String> getRuleKeywords();
/**
* Get Scenario keywords for this language
* @return List of translated "Scenario" keywords
*/
public List<String> getScenarioKeywords();
/**
* Get Scenario Outline keywords for this language
* @return List of translated "Scenario Outline" keywords
*/
public List<String> getScenarioOutlineKeywords();
/**
* Get Background keywords for this language
* @return List of translated "Background" keywords
*/
public List<String> getBackgroundKeywords();
/**
* Get Examples keywords for this language
* @return List of translated "Examples" keywords
*/
public List<String> getExamplesKeywords();
/**
* Get Given step keywords for this language
* @return List of translated "Given" step keywords
*/
public List<String> getGivenKeywords();
/**
* Get When step keywords for this language
* @return List of translated "When" step keywords
*/
public List<String> getWhenKeywords();
/**
* Get Then step keywords for this language
* @return List of translated "Then" step keywords
*/
public List<String> getThenKeywords();
/**
* Get And step keywords for this language
* @return List of translated "And" step keywords
*/
public List<String> getAndKeywords();
/**
* Get But step keywords for this language
* @return List of translated "But" step keywords
*/
public List<String> getButKeywords();
/**
* Get all step keywords for this language
* @return List of all step keywords (Given, When, Then, And, But)
*/
public List<String> getStepKeywords();
/**
* Get step keyword types for a specific keyword
* @param keyword step keyword to classify
* @return List of StepKeywordType classifications for the keyword
*/
public List<StepKeywordType> getStepKeywordTypes(String keyword);Language Examples:
// Explore English dialect
GherkinDialect english = provider.getDialect("en").get();
System.out.println("Language: " + english.getLanguage()); // "en"
System.out.println("Name: " + english.getName()); // "English"
System.out.println("Native: " + english.getNativeName()); // "English"
System.out.println("Feature keywords: " + english.getFeatureKeywords());
// Output: [Feature, Business Need, Ability]
System.out.println("Given keywords: " + english.getGivenKeywords());
// Output: [Given]
// Explore French dialect
GherkinDialect french = provider.getDialect("fr").get();
System.out.println("Language: " + french.getLanguage()); // "fr"
System.out.println("Name: " + french.getName()); // "French"
System.out.println("Native: " + french.getNativeName()); // "Français"
System.out.println("Feature keywords: " + french.getFeatureKeywords());
// Output: [Fonctionnalité]
System.out.println("Given keywords: " + french.getGivenKeywords());
// Output: [Soit, Étant donné, Étant donnée, Étant donnés, Étant données]
// Classify step keywords
List<StepKeywordType> givenTypes = english.getStepKeywordTypes("Given");
System.out.println("'Given' types: " + givenTypes);
// Output: [CONTEXT]
List<StepKeywordType> andTypes = english.getStepKeywordTypes("And");
System.out.println("'And' types: " + andTypes);
// Output: [CONJUNCTION]Use language dialects with parsing to handle multilingual feature files.
// Parse French feature file
GherkinDialectProvider frenchProvider = new GherkinDialectProvider("fr");
TokenMatcher matcher = new TokenMatcher(frenchProvider);
Parser<GherkinDocument> parser = new Parser<>(new GherkinDocumentBuilder(idGenerator, uri));
// The parser will automatically recognize French keywords
String frenchFeature = """
# language: fr
Fonctionnalité: Connexion utilisateur
Scénario: Identifiants valides
Soit un utilisateur existant
Quand il saisit des identifiants valides
Alors il devrait être connecté
""";
// Parser will handle language directive and French keywords
GherkinDocument doc = parser.parse(frenchFeature, "french.feature");Understand the semantic meaning of step keywords across languages.
// Step keyword semantic types
enum StepKeywordType {
CONTEXT, // Given - setup/preconditions
ACTION, // When - actions/events
OUTCOME, // Then - assertions/outcomes
CONJUNCTION, // And/But - continuation
UNKNOWN // ambiguous or unrecognized
}Classification Examples:
GherkinDialect dialect = provider.getDialect("en").get();
// Context keywords (Given)
dialect.getStepKeywordTypes("Given"); // [CONTEXT]
// Action keywords (When)
dialect.getStepKeywordTypes("When"); // [ACTION]
// Outcome keywords (Then)
dialect.getStepKeywordTypes("Then"); // [OUTCOME]
// Conjunction keywords (And/But)
dialect.getStepKeywordTypes("And"); // [CONJUNCTION]
dialect.getStepKeywordTypes("But"); // [CONJUNCTION]
// Check German dialect
GherkinDialect german = provider.getDialect("de").get();
german.getStepKeywordTypes("Gegeben sei"); // [CONTEXT]
german.getStepKeywordTypes("Wenn"); // [ACTION]
german.getStepKeywordTypes("Dann"); // [OUTCOME]
german.getStepKeywordTypes("Und"); // [CONJUNCTION]Install with Tessl CLI
npx tessl i tessl/maven-io-cucumber--gherkin