or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

index.mdlanguages.mdparsing.md

languages.mddocs/

0

# Language Support

1

2

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.

3

4

## Capabilities

5

6

### Dialect Provider

7

8

The GherkinDialectProvider manages language dialects and provides access to language-specific keywords.

9

10

```java { .api }

11

/**

12

* Create a dialect provider with English as default language

13

*/

14

public GherkinDialectProvider();

15

16

/**

17

* Create a dialect provider with custom default language

18

* @param defaultDialectName language code for default dialect (e.g., "en", "fr", "de")

19

*/

20

public GherkinDialectProvider(String defaultDialectName);

21

22

/**

23

* Get the default language dialect

24

* @return GherkinDialect for the default language

25

* @throws ParserException.NoSuchLanguageException if default language not found

26

*/

27

public GherkinDialect getDefaultDialect();

28

29

/**

30

* Get dialect for specific language

31

* @param language language code (e.g., "en", "fr", "de", "es")

32

* @return Optional containing dialect if language is supported

33

*/

34

public Optional<GherkinDialect> getDialect(String language);

35

36

/**

37

* Get all available language codes

38

* @return Set of supported language codes

39

*/

40

public Set<String> getLanguages();

41

```

42

43

**Usage Examples:**

44

45

```java

46

// Use default English dialect

47

GherkinDialectProvider provider = new GherkinDialectProvider();

48

GherkinDialect english = provider.getDefaultDialect();

49

50

// Use French as default

51

GherkinDialectProvider frenchProvider = new GherkinDialectProvider("fr");

52

GherkinDialect french = frenchProvider.getDefaultDialect();

53

54

// Check available languages

55

Set<String> languages = provider.getLanguages();

56

System.out.println("Supported languages: " + languages);

57

// Output: [en, fr, de, es, it, pt, ru, zh-CN, ja, ...]

58

59

// Get specific language dialect

60

Optional<GherkinDialect> spanish = provider.getDialect("es");

61

if (spanish.isPresent()) {

62

System.out.println("Spanish feature keywords: " +

63

spanish.get().getFeatureKeywords());

64

// Output: [Característica, Funcionalidad]

65

}

66

```

67

68

### Language Dialect

69

70

GherkinDialect provides access to language-specific keywords and metadata for a particular language.

71

72

```java { .api }

73

/**

74

* Get language code

75

* @return language code (e.g., "en", "fr", "de")

76

*/

77

public String getLanguage();

78

79

/**

80

* Get English name of the language

81

* @return English language name (e.g., "English", "French", "German")

82

*/

83

public String getName();

84

85

/**

86

* Get native name of the language

87

* @return native language name (e.g., "English", "Français", "Deutsch")

88

*/

89

public String getNativeName();

90

91

/**

92

* Get Feature keywords for this language

93

* @return List of translated "Feature" keywords

94

*/

95

public List<String> getFeatureKeywords();

96

97

/**

98

* Get Rule keywords for this language

99

* @return List of translated "Rule" keywords

100

*/

101

public List<String> getRuleKeywords();

102

103

/**

104

* Get Scenario keywords for this language

105

* @return List of translated "Scenario" keywords

106

*/

107

public List<String> getScenarioKeywords();

108

109

/**

110

* Get Scenario Outline keywords for this language

111

* @return List of translated "Scenario Outline" keywords

112

*/

113

public List<String> getScenarioOutlineKeywords();

114

115

/**

116

* Get Background keywords for this language

117

* @return List of translated "Background" keywords

118

*/

119

public List<String> getBackgroundKeywords();

120

121

/**

122

* Get Examples keywords for this language

123

* @return List of translated "Examples" keywords

124

*/

125

public List<String> getExamplesKeywords();

126

127

/**

128

* Get Given step keywords for this language

129

* @return List of translated "Given" step keywords

130

*/

131

public List<String> getGivenKeywords();

132

133

/**

134

* Get When step keywords for this language

135

* @return List of translated "When" step keywords

136

*/

137

public List<String> getWhenKeywords();

138

139

/**

140

* Get Then step keywords for this language

141

* @return List of translated "Then" step keywords

142

*/

143

public List<String> getThenKeywords();

144

145

/**

146

* Get And step keywords for this language

147

* @return List of translated "And" step keywords

148

*/

149

public List<String> getAndKeywords();

150

151

/**

152

* Get But step keywords for this language

153

* @return List of translated "But" step keywords

154

*/

155

public List<String> getButKeywords();

156

157

/**

158

* Get all step keywords for this language

159

* @return List of all step keywords (Given, When, Then, And, But)

160

*/

161

public List<String> getStepKeywords();

162

163

/**

164

* Get step keyword types for a specific keyword

165

* @param keyword step keyword to classify

166

* @return List of StepKeywordType classifications for the keyword

167

*/

168

public List<StepKeywordType> getStepKeywordTypes(String keyword);

169

```

170

171

**Language Examples:**

172

173

```java

174

// Explore English dialect

175

GherkinDialect english = provider.getDialect("en").get();

176

System.out.println("Language: " + english.getLanguage()); // "en"

177

System.out.println("Name: " + english.getName()); // "English"

178

System.out.println("Native: " + english.getNativeName()); // "English"

179

180

System.out.println("Feature keywords: " + english.getFeatureKeywords());

181

// Output: [Feature, Business Need, Ability]

182

183

System.out.println("Given keywords: " + english.getGivenKeywords());

184

// Output: [Given]

185

186

// Explore French dialect

187

GherkinDialect french = provider.getDialect("fr").get();

188

System.out.println("Language: " + french.getLanguage()); // "fr"

189

System.out.println("Name: " + french.getName()); // "French"

190

System.out.println("Native: " + french.getNativeName()); // "Français"

191

192

System.out.println("Feature keywords: " + french.getFeatureKeywords());

193

// Output: [Fonctionnalité]

194

195

System.out.println("Given keywords: " + french.getGivenKeywords());

196

// Output: [Soit, Étant donné, Étant donnée, Étant donnés, Étant données]

197

198

// Classify step keywords

199

List<StepKeywordType> givenTypes = english.getStepKeywordTypes("Given");

200

System.out.println("'Given' types: " + givenTypes);

201

// Output: [CONTEXT]

202

203

List<StepKeywordType> andTypes = english.getStepKeywordTypes("And");

204

System.out.println("'And' types: " + andTypes);

205

// Output: [CONJUNCTION]

206

```

207

208

### Language-Aware Parsing

209

210

Use language dialects with parsing to handle multilingual feature files.

211

212

```java

213

// Parse French feature file

214

GherkinDialectProvider frenchProvider = new GherkinDialectProvider("fr");

215

TokenMatcher matcher = new TokenMatcher(frenchProvider);

216

Parser<GherkinDocument> parser = new Parser<>(new GherkinDocumentBuilder(idGenerator, uri));

217

218

// The parser will automatically recognize French keywords

219

String frenchFeature = """

220

# language: fr

221

Fonctionnalité: Connexion utilisateur

222

Scénario: Identifiants valides

223

Soit un utilisateur existant

224

Quand il saisit des identifiants valides

225

Alors il devrait être connecté

226

""";

227

228

// Parser will handle language directive and French keywords

229

GherkinDocument doc = parser.parse(frenchFeature, "french.feature");

230

```

231

232

### Step Keyword Classification

233

234

Understand the semantic meaning of step keywords across languages.

235

236

```java { .api }

237

// Step keyword semantic types

238

enum StepKeywordType {

239

CONTEXT, // Given - setup/preconditions

240

ACTION, // When - actions/events

241

OUTCOME, // Then - assertions/outcomes

242

CONJUNCTION, // And/But - continuation

243

UNKNOWN // ambiguous or unrecognized

244

}

245

```

246

247

**Classification Examples:**

248

249

```java

250

GherkinDialect dialect = provider.getDialect("en").get();

251

252

// Context keywords (Given)

253

dialect.getStepKeywordTypes("Given"); // [CONTEXT]

254

255

// Action keywords (When)

256

dialect.getStepKeywordTypes("When"); // [ACTION]

257

258

// Outcome keywords (Then)

259

dialect.getStepKeywordTypes("Then"); // [OUTCOME]

260

261

// Conjunction keywords (And/But)

262

dialect.getStepKeywordTypes("And"); // [CONJUNCTION]

263

dialect.getStepKeywordTypes("But"); // [CONJUNCTION]

264

265

// Check German dialect

266

GherkinDialect german = provider.getDialect("de").get();

267

german.getStepKeywordTypes("Gegeben sei"); // [CONTEXT]

268

german.getStepKeywordTypes("Wenn"); // [ACTION]

269

german.getStepKeywordTypes("Dann"); // [OUTCOME]

270

german.getStepKeywordTypes("Und"); // [CONJUNCTION]

271

```