A build task to translate JSON files to other languages using Google's Translation API. Pairs very well with angular-translate.
Massive thanks to MartyIce for allowing me to use the grunt-google-translate namespace.
This plugin requires Grunt
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-google-translate --save-dev
In your project's Gruntfile, add a section named
google_translate to the data object passed into
The API key used to access Google Translation services.
In this example, I passed in a JSON file with english text. It will then create two files in the
i18n/ folder called ru.json and zh-CN.json for Russian and Chinese respectively.
Note: This plugin will try and deduce the suffix (file type), so you don't need to explicity specify it. If you need it to have a different suffix, then specify the
suffix as shown in the next example.
In this example, two files are being translated, one called
locale-en.json and another called
locale-fr.json. They are in different folders, and will create translated files in the same
Notice how the prefix and suffix is specified, it means the translated files will be named like
locale-de.json instead of
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.