Security update for permissions_by_term
[yaffs-website] / vendor / behat / gherkin / bin / update_i18n
1 #!/usr/bin/env php
2 <?php
3
4 $gherkinUrl = 'https://raw.githubusercontent.com/cucumber/cucumber/master/gherkin/gherkin-languages.json';
5 $json  = file_get_contents($gherkinUrl);
6 $array = array();
7
8 foreach (json_decode($json, true) as $lang => $keywords) {
9     $langMessages = array();
10
11     foreach ($keywords as $type => $words) {
12         if (!is_array($words)) {
13             $words = array($words);
14         }
15
16         if ('scenarioOutline' === $type) {
17             $type = 'scenario_outline';
18         }
19
20         if (in_array($type, array('given', 'when', 'then', 'and', 'but'))) {
21             $formattedKeywords = array();
22
23             foreach ($words as $word) {
24                 $formattedWord = trim($word);
25
26                 if ($formattedWord === $word) {
27                     $formattedWord = $formattedWord.'<'; // Convert the keywords to the syntax used by Gherkin 2, which is expected by our Lexer.
28                 }
29
30                 $formattedKeywords[] = $formattedWord;
31             }
32
33             $words = $formattedKeywords;
34         }
35
36         usort($words, function($type1, $type2) {
37             return mb_strlen($type2, 'utf8') - mb_strlen($type1, 'utf8');
38         });
39
40         $langMessages[$type] = implode('|', $words);
41     }
42
43     // ensure that the order of keys is consistent between updates
44     ksort($langMessages);
45
46     $array[$lang] = $langMessages;
47 }
48
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'];
51 unset($array['en']);
52 ksort($array);
53 $array = array_merge(array('en' => $enData), $array);
54 $arrayString = var_export($array, true);
55
56 file_put_contents(__DIR__.'/../i18n.php', <<<EOD
57 <?php
58
59 /*
60  * DO NOT TOUCH THIS FILE!
61  *
62  * This file is automatically generated by `bin/update_i18n`.
63  * Actual Gherkin translations live in cucumber/gherkin repo:
64  * {$gherkinUrl}
65  * Please send your translation changes there.
66  */
67
68 return $arrayString;
69 EOD
70 );