2018-11-20 14:39:00 +00:00
|
|
|
var { safeLoad, safeDump } = require('js-yaml')
|
2018-02-26 10:55:55 +00:00
|
|
|
var fs = require('fs')
|
2018-03-05 16:00:47 +00:00
|
|
|
var path = require('path')
|
|
|
|
let R = require('ramda')
|
2018-02-26 10:55:55 +00:00
|
|
|
|
2018-03-06 16:16:30 +00:00
|
|
|
let externalizationPath = 'source/règles/externalized.yaml'
|
2018-02-26 12:47:29 +00:00
|
|
|
|
2018-11-20 14:39:00 +00:00
|
|
|
let rules = safeLoad(
|
2018-03-05 16:00:47 +00:00
|
|
|
fs.readFileSync(path.resolve('source/règles/base.yaml'), 'utf-8')
|
|
|
|
)
|
2018-02-26 10:55:55 +00:00
|
|
|
|
2018-11-20 14:39:00 +00:00
|
|
|
let currentExternalization = safeLoad(
|
2018-03-06 16:16:30 +00:00
|
|
|
fs.readFileSync(path.resolve(externalizationPath), 'utf-8')
|
|
|
|
)
|
|
|
|
|
2018-03-05 16:00:47 +00:00
|
|
|
let attributesToExternalize = [
|
|
|
|
'titre',
|
|
|
|
'description',
|
|
|
|
'question',
|
2018-08-30 09:11:34 +00:00
|
|
|
'résumé',
|
2019-04-10 13:41:56 +00:00
|
|
|
'suggestions',
|
|
|
|
'contrôles'
|
2018-03-05 16:00:47 +00:00
|
|
|
]
|
2018-02-26 10:55:55 +00:00
|
|
|
|
2018-03-06 16:16:30 +00:00
|
|
|
let buildDottedName = rule =>
|
|
|
|
rule.espace ? rule.espace + ' . ' + rule.nom : rule.nom
|
|
|
|
|
2019-04-09 17:01:59 +00:00
|
|
|
let resolved = rules
|
2018-03-05 16:00:47 +00:00
|
|
|
.map(rule => (!rule.titre ? { ...rule, titre: rule.nom } : rule))
|
2019-04-09 17:01:59 +00:00
|
|
|
.map(rule => ({
|
|
|
|
[buildDottedName(rule)]: R.mergeAll(
|
|
|
|
R.toPairs(rule)
|
2019-07-16 13:08:57 +00:00
|
|
|
.filter(([, v]) => !!v)
|
2019-04-09 17:01:59 +00:00
|
|
|
.map(([k, v]) => {
|
|
|
|
let attrToTranslate = attributesToExternalize.find(R.equals(k))
|
|
|
|
if (!attrToTranslate) return {}
|
|
|
|
let enTrad = attrToTranslate + '.en',
|
|
|
|
frTrad = attrToTranslate + '.fr'
|
|
|
|
|
|
|
|
let currentTranslation = currentExternalization[buildDottedName(rule)]
|
|
|
|
//Check if a human traduction exists already for this attribute
|
|
|
|
if (currentTranslation && currentTranslation[enTrad])
|
|
|
|
return {
|
|
|
|
[enTrad]: currentTranslation[enTrad],
|
|
|
|
[frTrad]: v
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
[enTrad]: '!!' + v,
|
2018-03-06 16:16:30 +00:00
|
|
|
[frTrad]: v
|
2019-04-09 17:01:59 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}))
|
|
|
|
fs.writeFileSync(externalizationPath, safeDump(R.mergeAll(resolved)))
|