Skip to content

Commit

Permalink
fix: handle digit keys in CSV translation files
Browse files Browse the repository at this point in the history
  • Loading branch information
friedjoff committed Sep 9, 2020
1 parent b4b0111 commit 6a24df9
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/i18n/convert2json.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ const fr = {};
const records = parse(data);
records.shift(); // remove header
await records.forEach(([key, german, french]) => {
set(de, key.split('.'), german);
set(fr, key.split('.'), french);
const keys = key.split('.');
// handle digit keys
if (keys[keys.length - 1].match(/^\d*$/)) {
keys[keys.length - 1] = `"${keys[keys.length - 1]}"`;
}
set(de, keys, german);
set(fr, keys, french);
});
const dePath = path.join(__dirname, 'resources', 'de', 'translation.json');
const frPath = path.join(__dirname, 'resources', 'fr', 'translation.json');
await fs.writeFile(dePath, JSON.stringify(de, null, 2));
await fs.writeFile(frPath, JSON.stringify(fr, null, 2));
await fs.writeFile(dePath, JSON.stringify(de, null, 2).replace(/\\"/g, ''));
await fs.writeFile(frPath, JSON.stringify(fr, null, 2).replace(/\\"/g, ''));
})();

0 comments on commit 6a24df9

Please sign in to comment.