2018-02-26 10:55:55 +00:00
|
|
|
var yaml = require('js-yaml')
|
|
|
|
var fs = require('fs')
|
2018-03-05 16:00:47 +00:00
|
|
|
var translate = require('google-translate-api')
|
|
|
|
var path = require('path')
|
|
|
|
let R = require('ramda')
|
2018-02-26 10:55:55 +00:00
|
|
|
|
2018-03-05 16:00:47 +00:00
|
|
|
translate(
|
|
|
|
'Bonjour, je suis votre agent traducteur. Je vais traduire votre application, puis ensuite dominer le monde',
|
|
|
|
{ from: 'fr', to: 'en' }
|
|
|
|
)
|
|
|
|
.then(res => {
|
|
|
|
console.log(res.text)
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.error(err)
|
|
|
|
})
|
2018-02-26 12:47:29 +00:00
|
|
|
|
2018-03-05 16:00:47 +00:00
|
|
|
rules = yaml.safeLoad(
|
|
|
|
fs.readFileSync(path.resolve('source/règles/base.yaml'), 'utf-8')
|
|
|
|
)
|
2018-02-26 10:55:55 +00:00
|
|
|
|
2018-03-05 16:00:47 +00:00
|
|
|
let attributesToExternalize = [
|
|
|
|
'titre',
|
|
|
|
'description',
|
|
|
|
'question',
|
|
|
|
'sous-question',
|
|
|
|
'résumé'
|
|
|
|
]
|
2018-02-26 10:55:55 +00:00
|
|
|
|
2018-03-05 16:00:47 +00:00
|
|
|
let promises = rules
|
|
|
|
.map(rule => (!rule.titre ? { ...rule, titre: rule.nom } : rule))
|
|
|
|
.map(rule =>
|
|
|
|
Promise.all(
|
|
|
|
R.toPairs(rule).map(([k, v]) => {
|
|
|
|
let attrToTranslate = attributesToExternalize.find(R.equals(k))
|
|
|
|
if (!attrToTranslate) return Promise.resolve({})
|
|
|
|
return translate(v, { from: 'fr', to: 'en' }).then(({ text }) => ({
|
|
|
|
[attrToTranslate + '.fr']: v,
|
|
|
|
[attrToTranslate + '.en']: text
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
).then(attributes => {
|
|
|
|
let id = rule.espace ? rule.espace + ' . ' + rule.nom : rule.nom
|
|
|
|
return { [id]: R.mergeAll(attributes) }
|
|
|
|
})
|
|
|
|
)
|
2018-02-26 12:47:29 +00:00
|
|
|
|
2018-03-05 16:00:47 +00:00
|
|
|
Promise.all(promises).then(resolved =>
|
|
|
|
fs.writeFileSync(
|
|
|
|
'source/règles/externalized.yaml',
|
|
|
|
yaml.safeDump(R.mergeAll(resolved))
|
|
|
|
)
|
2018-02-26 10:55:55 +00:00
|
|
|
)
|