5

I have 2 files en.json and xx.json with translations in Angular application. Common idea is to create translation in both files for multilanguage application, but sometimes some programmers adding translation just in one of these file, because they testing app only in their language.

I am looking for tool that check same structure in both JSON files, otherwise it throw error and it helps with addition when you creating translations for second language. Do you know any good practices, tools or plugins for this? I am using WebStorm.

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Gregor Albert
  • 819
  • 1
  • 11
  • 23
  • "attranslate" is a modern tool that is specifically designed for comparing and synchronizing JSON-files: https://github.com/fkirc/attranslate – Mike76 Nov 21 '20 at 06:38

3 Answers3

4

Use a small Node.js script

Since you already have Angular installed (which means you have NPM & Node.Js), you can find inconsistencies in your translation JSON files with a script. Here's how it looks

Code

const fs = require('fs');

// Define your file paths here
const files = ['./english.json', './russian.json']

// Read contents and parse JSON
const filesWithKeys = files.map(f => ({
  name: f,
  content: JSON.parse(fs.readFileSync(f, 'utf8'))
}));

// Gather all the keys used in all files in one array
const allKeys = filesWithKeys.map(f => Object.keys(f.content)).flat();

// Find the missing keys by file
const missingKeysByFile = filesWithKeys.map(f => ({
  name: f.name,
  missingKeys: allKeys.filter(k => !(k in f.content))
})).filter(f => f.missingKeys.length > 0);


// Print the result
missingKeysByFile.forEach(f => {
  console.log(`File "${f.name}" is missing keys [ ${f.missingKeys.join(' ')} ]`);
});

Sample output

File "english.json" is missing keys [ appTitle, contentHeader ]
File "russian.json" is missing keys [ usernameHint ]
molamk
  • 4,076
  • 1
  • 13
  • 22
1

Try POEditor. It's free up to 1000 strings.

1

You can check Pootle (http://pootle.translatehouse.org/index.html) or Poedit (https://poedit.net) or POEditor (https://poeditor.com/)

Ankur Jain
  • 221
  • 1
  • 6