node package manager
Don’t reinvent the wheel. Reuse code within your team. Create a free org »

grunt-djangularjs-translate

Grunt tasks to automatically extract translations from your djangularjs project

Status

Stable

Build Status

Getting Started

npm install grunt-djangularjs-translate

NOTE: This extraction tool is made to work with the djangularjs framework.

Example

The configuration below generates 2 translation files:

  • public/i18n/en.js
  • public/i18n/fr.js file
// gruntfile.js  
module.exports = function(grunt) {
    require('load-grunt-tasks')(grunt);
    grunt.initConfig({
        // ... 
        translate: {
            all: {
                src: [
                    "public/*[!_]*/*.js",
                    "public/*[!_]*/*[!tests]*/*.js",
                    "public/*[!_]*/*[!tests]*/*.html"
                ],
                lang: ['en', 'fr'],
                dest: 'i18n',
                moduleName: 'core'
            }
        },
        // ... 
    });
}
// public/i18n/en.js 
angular
    .module('core')
    .config(['$translateProvider', function($translateProvider) {
        $translateProvider.translations('en', {
            key1: 'trans1-en',
            // ... 
        });
    }]);
 
// public/i18n/fr.js 
angular
    .module('core')
    .config(['$translateProvider', function($translateProvider) {
        $translateProvider.translations('fr', {
            key1: 'trans1-fr',
            // ... 
        });
    }]);
 

Options

src

List files containing the translations.

Type: Array

Default:

[
  "public/*[!_]*/*.js",
  "public/*[!_]*/*[!tests]*/*.js",
  "public/*[!_]*/*[!tests]*/*.html
]

lang

Define used languages.

Type: Array

Default: ['en']

dest

Name of the translations folder.

Type: String

Default: 'i18n'

moduleName

Name of the angular module mainModule.

Type: String

Default: 'core'

Test

You will find the tests files into test directory.

To run test use grunt test

Credits

Inspired from grunt-angular-translate.

License

The MIT License (MIT)

Copyright (c) 2015-2016 Nicolas Panel