forked from electron/i18n
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload-crowdin-glossary.js
73 lines (61 loc) · 2.1 KB
/
upload-crowdin-glossary.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
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
#!/usr/bin/env node
require('dotenv-safe').config()
const assert = require('assert')
const globals = require('globals')
const electronApis = require('../content/en-US/electron-api.json')
const parseElectronGlossary = require('../lib/parse-electron-glossary')
main()
async function main() {
const glossary = require('crowdin-glossary')({ project: 'electron' })
// JavaScript builtins like Array, Map, String, etc
Object.keys(globals.builtin).forEach(term => {
if (Object.keys(glossary.entries).includes(term)) return
glossary.add(
term,
'This is a JavaScript builtin and should usually not be translated.'
)
})
// Electron API names
electronApis.forEach(api => {
glossary.add(
api.name,
`This is an Electron ${api.type} and should usually not be translated`
)
})
// Electron instance methods and properties
electronApis
.filter(api => api.type === 'Class')
.forEach(api => {
const methods = api.instanceMethods || []
methods.forEach(method => {
const term = `${api.instanceName}.${method.name}`
if (Object.keys(glossary.entries).includes(term)) return
glossary.add(
term,
'This is an Electron instance method and should usually not be translated'
)
})
const props = api.instanceProperties || []
props.forEach(prop => {
const term = `${api.instanceName}.${prop.name}`
if (Object.keys(glossary.entries).includes(term)) return
glossary.add(
term,
'This is an Electron instance property and should usually not be translated'
)
})
})
// Electron Jargon like `IPC`, `Main Process`, etc
Object.values(await parseElectronGlossary('en-US')).forEach(entry => {
if (Object.keys(glossary.entries).includes(entry.term)) return
glossary.add(entry.term, entry.description)
})
// Validate
const minEntries = 400
const entryCount = Object.keys(glossary.entries).length
assert(
entryCount >= minEntries,
`glossary should have more than ${minEntries} entries but only has ${entryCount}`
)
glossary.upload()
}