Search code examples
ember-cli

Include .json file in .js module


I have a translations file at:

frontend/locales/en/translations.js

which looks like:

export default {
  back: "Back",
  or: "Or",
  cancel: "Cancel",
};

I want to move the translations hash into a .json file:

frontend/locales/en/translations.json

and somehow include it in the .js file.

What's the best way to do this?


Solution

  • I found a pretty slick solution: ember-cli-json-module.

    After installing this add-on, I can do:

    // master.json:
    {
      "back": "Back",
      "or": "Or",
      "cancel": "Cancel"
    }
    
    // translations.js:
    import masterFile from './master';
    
    export default masterFile;
    

    I also removed the EcmaScript6 tag, as this is a specifically ember-cli solution.