title: Testing JSON translation files with Jasmine
body: <p>I'm using the ngx-translate library to provide multiple languages on an Angular application. After finding a couple of missing translated strings when switching the language, I decided to add some basic tests to the files containing the translated strings. Basically, I want to test that all the language files have the same keys.</p>
  <p>My translation files are separated in several folders: <code>app</code>, <code>labels</code> and <code>wizards</code> (so far), with each folder containing an <code>es.json</code> and <code>en.json</code> file. To test all the files, this is what I do:</p>
  <p><strong>i18n.spec.ts</strong></p>
  <pre class="lang-js prettyprint-override"><code>fdescribe(&quot;i18n language files tests&quot;, () =&gt; {
    // Global app translations
    let appEs: any;
    let appEn: any;
    // Panels translations
    let panelsEs: any;
    let panelsEn: any;
    // Wizards translations
    let wizardsEs: any;
    let wizardsEn: any;
  
    beforeEach(() =&gt; {
      appEs = require('./app/es.json');
      appEn = require('./app/en.json');
  
      panelsEs = require('./panels/es.json');
      panelsEn = require('./panels/en.json');
  
      wizardsEs = require('./wizards/es.json');
      wizardsEn = require('./wizards/en.json');
    });
  
    it('should have the same keys for all language files', () =&gt; {
      // Global app translations
      let keysEs = getObjKeys(appEs);
      let keysEn = getObjKeys(appEn);
          
      expect(findMissingKeys(appEn, keysEs)).toEqual([]);
      expect(findMissingKeys(appEs, keysEn)).toEqual([]);
  
      // Panels translations
      keysEs = getObjKeys(panelsEs);
      keysEn = getObjKeys(panelsEn);
          
      expect(findMissingKeys(panelsEn, keysEs)).toEqual([]);
      expect(findMissingKeys(panelsEs, keysEn)).toEqual([]);
  
      // Wizards translations
      keysEs = getObjKeys(wizardsEs);
      keysEn = getObjKeys(wizardsEn);
          
      expect(findMissingKeys(wizardsEn, keysEs)).toEqual([]);
      expect(findMissingKeys(wizardsEs, keysEn)).toEqual([]);
    });
  });
  </code></pre>
  <p>As you can see, I load each JSON file using <code>require</code> and then, for each pair of language &quot;sections&quot; (app, panels, wizards) I get its keys and I make sure that both languages have exactly the same.</p>
  <p>This is working fine, but, as <code>require</code> doesn't work with variables, the code it's quite repetitive and adding a new language subfolder is really cumbersome, as I have to add it in several parts of the code.</p>
  <p>Any ideas on how I could simplify this process? Thanks!</p>