-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18n.ts
81 lines (72 loc) · 2.73 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import {info} from './info.ts'
/**
* A big object containing all our internationalization
*/
const languages: I18N = {
english: {
unknownOption: '${this.executable}: unknown option ${this.flag}',
useHelp: 'Use ${this.executable} --help for help with command-line options',
helpMessage: [
'${this.executable} - commandline JSON, YAML and TOML processor [version ${this.info.version}]',
'Usage: ${this.executable} [options] <filter> [file]',
'',
...[
'Aqueous (${this.executable}) is a tool for processing many input types, applying a given filter to its inputs,',
'and responding with the filter\'s results as the given format (JSON by default)',
'',
'Options:',
...[
{
flags: ['--help'],
description: 'Displays this help message'
},
{
flags: ['--compact', '-c'],
description: 'Compact mode'
},
{
flags: ['--json', '-j'],
description: 'Outputs in JSON'
},
{
flags: ['--toml', '-t'],
description: 'Outputs in TOML'
},
{
flags: ['--yaml', '-y'],
description: 'Outputs in YAML'
},
{
flags: ['--color', '-c'],
description: 'Output in color'
}
].map(z=> z.flags.join(", ").padEnd(20,' ') + z.description)
].map(z=>'\t' + z)
].join('\n'),
formatNotDetected: 'format error: Could not detect format of input',
formatNoMatch: 'format error: Format of input does not match ${this.format}'
}
}
//Actual code
interface I18NLanguage {
unknownOption: string,
useHelp: string,
helpMessage: string,
formatNotDetected: string,
formatNoMatch: string,
[key: string]: string
}
interface I18N {
english: I18NLanguage,
[key: string]: I18NLanguage
}
const language: string = 'english' //I have no idea how to update this dynamically Sorry 😶
const baseTemplate = {
executable: 'aq',
info: info
}
export function i18n(key: string, template?: any) : string{
let myLanguage: I18NLanguage = languages[language];
let str: string = myLanguage[key];
return new Function("return `" + str + "`;").call({...template, ...baseTemplate})
}