From e3d7f07275e164bcfc18ec64a6f72125a16ee68d Mon Sep 17 00:00:00 2001 From: Dmytro Gorelik Date: Wed, 7 Jun 2017 16:07:51 +0300 Subject: [PATCH] preserve context while exporting json-properties --- exporters/json-properties.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/exporters/json-properties.js b/exporters/json-properties.js index a847cfe..e377b91 100755 --- a/exporters/json-properties.js +++ b/exporters/json-properties.js @@ -2,9 +2,21 @@ var fs = require('fs'); function convertListToMap(list) { var termToTranslationMap = {}; + list.forEach(function (t) { - termToTranslationMap[t.term] = t.definition.form; + var form = t.definition.form; + var term = t.term; + var context = t.context.replace(/^"(.*)"$/, '$1'); + + if (context && !termToTranslationMap[context]) { + termToTranslationMap[context] = {}; + } + + context + ? termToTranslationMap[context][term] = form + : termToTranslationMap[term] = form; }); + return termToTranslationMap; }