parent
7af1f60ded
commit
c8b61361f8
|
@ -23,6 +23,7 @@
|
|||
"flow": "^0.2.3",
|
||||
"fuse.js": "^3.2.0",
|
||||
"global": "^4.3.2",
|
||||
"google-translate-api": "^2.3.0",
|
||||
"ignore-loader": "^0.1.2",
|
||||
"js-yaml": "^3.9.1",
|
||||
"marked": "^0.3.9",
|
||||
|
|
|
@ -1,33 +1,53 @@
|
|||
var yaml = require('js-yaml')
|
||||
var fs = require('fs')
|
||||
var translate = require('google-translate-api')
|
||||
var path = require('path')
|
||||
let R = require('ramda')
|
||||
|
||||
rules = yaml.safeLoad(fs.readFileSync('source/règles/base.yaml','utf-8'))
|
||||
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)
|
||||
})
|
||||
|
||||
externalized = {}
|
||||
|
||||
rules.map(
|
||||
rule => {
|
||||
let externalizeProp = (rule, prop, result) => {
|
||||
if (rule[prop]) {
|
||||
result[prop+".fr"] = result[prop+".en"] = rule[prop]
|
||||
result[prop+".en"] = result[prop+".en"].split("").reverse().join("")
|
||||
}
|
||||
}
|
||||
|
||||
// Toujours traduire le nom via titre
|
||||
if (!rule["titre"]) rule["titre"] = rule["nom"]
|
||||
|
||||
var externKey = rule.espace ?
|
||||
rule.espace + " . " + rule.nom :
|
||||
rule.nom
|
||||
var result = externalized[externKey] = {}
|
||||
|
||||
externalizeProp(rule,"titre",result)
|
||||
externalizeProp(rule,"description",result)
|
||||
externalizeProp(rule,"question",result)
|
||||
externalizeProp(rule,"sous-question",result)
|
||||
return result
|
||||
}
|
||||
rules = yaml.safeLoad(
|
||||
fs.readFileSync(path.resolve('source/règles/base.yaml'), 'utf-8')
|
||||
)
|
||||
|
||||
fs.writeFileSync('source/règles/externalized.yaml', yaml.safeDump(externalized))
|
||||
let attributesToExternalize = [
|
||||
'titre',
|
||||
'description',
|
||||
'question',
|
||||
'sous-question',
|
||||
'résumé'
|
||||
]
|
||||
|
||||
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) }
|
||||
})
|
||||
)
|
||||
|
||||
Promise.all(promises).then(resolved =>
|
||||
fs.writeFileSync(
|
||||
'source/règles/externalized.yaml',
|
||||
yaml.safeDump(R.mergeAll(resolved))
|
||||
)
|
||||
)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue