4 $gherkinUrl = 'https://raw.githubusercontent.com/cucumber/cucumber/master/gherkin/gherkin-languages.json';
5 $json = file_get_contents($gherkinUrl);
8 foreach (json_decode($json, true) as $lang => $keywords) {
9 $langMessages = array();
11 foreach ($keywords as $type => $words) {
12 if (!is_array($words)) {
13 $words = array($words);
16 if ('scenarioOutline' === $type) {
17 $type = 'scenario_outline';
20 if (in_array($type, array('given', 'when', 'then', 'and', 'but'))) {
21 $formattedKeywords = array();
23 foreach ($words as $word) {
24 $formattedWord = trim($word);
26 if ($formattedWord === $word) {
27 $formattedWord = $formattedWord.'<'; // Convert the keywords to the syntax used by Gherkin 2, which is expected by our Lexer.
30 $formattedKeywords[] = $formattedWord;
33 $words = $formattedKeywords;
36 usort($words, function($type1, $type2) {
37 return mb_strlen($type2, 'utf8') - mb_strlen($type1, 'utf8');
40 $langMessages[$type] = implode('|', $words);
43 // ensure that the order of keys is consistent between updates
46 $array[$lang] = $langMessages;
49 // ensure that the languages are sorted to avoid useless diffs between updates. We keep the English first though as it is the reference.
50 $enData = $array['en'];
53 $array = array_merge(array('en' => $enData), $array);
54 $arrayString = var_export($array, true);
56 file_put_contents(__DIR__.'/../i18n.php', <<<EOD
60 * DO NOT TOUCH THIS FILE!
62 * This file is automatically generated by `bin/update_i18n`.
63 * Actual Gherkin translations live in cucumber/gherkin repo:
65 * Please send your translation changes there.