-
Notifications
You must be signed in to change notification settings - Fork 3
/
generate-languages.js
48 lines (37 loc) · 1 KB
/
generate-languages.js
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
/* eslint-disable @typescript-eslint/no-var-requires */
/* This script file generates languages, and prepares them for translation */
const ISO6391 = require('iso-639-1')
const { inspect } = require('util')
const fs = require('fs')
const prettier = require('prettier')
const path = require('path')
let prettierConfig
;(async () => {
prettierConfig = await prettier.resolveConfig(
path.resolve(__dirname, '../.prettierrc.js')
)
})()
const result = ISO6391.getAllNames().map((lang) => {
return {
raw: lang,
t: `${lang}`
}
})
const dir = `${__dirname}/../src/generated`
fs.mkdirSync(dir, { recursive: true })
const file = fs.createWriteStream(`${dir}/languages.js`)
const data = `
import { t } from '@lingui/macro'
export function languages(){
const data = ${inspect(result, { maxArrayLength: null }).replace(
/t: '(?<name>.*)'/g,
't: t`$<name>`'
)}
return data
}`
const formatted = prettier.format(data, {
...prettierConfig,
parser: 'babel'
})
file.write(formatted)
file.end()