-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathlinguifix.js
More file actions
34 lines (24 loc) · 1.29 KB
/
Copy pathlinguifix.js
File metadata and controls
34 lines (24 loc) · 1.29 KB
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
const { readdir, readFile, writeFile } = require('fs')
const { promisify } = require('util')
const { bindKey, mapValues } = require('lodash')
const { formatter: createPoFormatter } = require('@lingui/format-po')
const { formatter: createJsonFormatter } = require('@lingui/format-json')
const poFormatter = createPoFormatter()
const jsonFormatter = createJsonFormatter({ style: 'lingui' })
const [readdirAsync, readFileAsync, writeFileAsync] = [readdir, readFile, writeFile].map(promisify)
const [parseJSON, parsePO] = [jsonFormatter, poFormatter].map(formatter => bindKey(formatter, 'parse'))
readdirAsync('src/language/locales')
.then(async dir => Promise.all(dir.map(async item => {
const path = `src/language/locales/${item}/`
const poPath = path + 'catalog.po'
const catalog = await readFileAsync(path + 'catalog.json.bak', 'utf8').then(parseJSON)
const poCatalog = await readFileAsync(poPath, 'utf8').then(parsePO)
const newCatalog = mapValues(poCatalog, item => {
const { message } = item
const translation = catalog[message]
return !translation || translation === message ? item : { ...item, translation }
})
const output = poFormatter.serialize(newCatalog, {})
await writeFileAsync(poPath, output)
})))
.then(() => console.log('done'))