-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
i18n.ts
65 lines (61 loc) · 1.44 KB
/
i18n.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import _ from 'lodash'
import Gherkin from 'gherkin'
import Table, { HorizontalTable } from 'cli-table3'
import { capitalCase } from 'capital-case'
const keywords = [
'feature',
'background',
'scenario',
'scenarioOutline',
'examples',
'given',
'when',
'then',
'and',
'but',
] as const
function getAsTable(header: string[], rows: string[][]): string {
const table = new Table({
chars: {
bottom: '',
'bottom-left': '',
'bottom-mid': '',
'bottom-right': '',
left: '',
'left-mid': '',
mid: '',
'mid-mid': '',
middle: ' | ',
right: '',
'right-mid': '',
top: '',
'top-left': '',
'top-mid': '',
'top-right': '',
},
style: {
border: [],
'padding-left': 0,
'padding-right': 0,
},
}) as HorizontalTable
table.push(header)
table.push(...rows)
return table.toString()
}
export function getLanguages(): string {
const rows = _.map(Gherkin.dialects(), (data, isoCode) => [
isoCode,
data.name,
data.native,
])
return getAsTable(['ISO 639-1', 'ENGLISH NAME', 'NATIVE NAME'], rows)
}
export function getKeywords(isoCode: string): string {
const language = Gherkin.dialects()[isoCode]
const rows = _.map(keywords, keyword => {
const words = _.map(language[keyword], s => `"${s}"`).join(', ')
return [capitalCase(keyword), words]
})
return getAsTable(['ENGLISH KEYWORD', 'NATIVE KEYWORDS'], rows)
}