@poool/grunt-angular-translate-cache v0.1.1
grunt-angular-translate-cache
Grunt build task to concatenate & pre-load your Angular Translate translations using $translationCache
Output example :
angular.module('test-app').run(['$translationCache', function($translationCache) {
$translationCache.put("languages/en.json", {"test":"This is a <span class=\"test\">test</span>"});
$translationCache.put("languages/fr.json", {"test":"Ceci est un test"});
}]);Then, when you use a translation file with angular-translate-loader-static-files it will already be loaded without having to do another Ajax request !
Installation
This plugin requires Grunt ~1.0.0
Usemin integration requires grunt-usemin ~3.0.0
Install the plugin :
- NPM :
$ npm install @poool/grunt-angular-translate-cache --save-dev - Yarn :
$ yarn add @poool/grunt-angular-translate-cache
Enable the plugin within your Gruntfile :
grunt.loadNpmTasks("@poool/grunt-angular-translate-cache");Options
angular
Global namespace for Angular.
If you use angular.noConflict(), then set this value to whatever you
re-assign angular to. Otherwise, it defaults to angular.
bootstrap
Callback to modify the bootstraper that registers lang files with
$translationCache.
By default, the bootstrap script wraps function($translationCache) { ... } with:
angular.module('app').run(['$translationCache', ... ]);If you want to create your own wrapper so you register the templates as an
AMD or CommonJS module, set the bootstrap option to something like:
bootstrap: function(module, script) {
return 'module.exports[module] = ' + script + ';';
}module
Stringof theangular.moduleto register templates with.
If not specified, it will automatically be the name of the ngTranslateCache
subtask (e.g. app, based on the examples below).
prefix
Stringto prefix template URLs with. Defaults to''
If you need to use absolute urls:
ngTranslateCache: {
app: {
options: {
prefix: '/'
}
}
}If you serve static assets from another directory, you specify that as well.
standalone
Boolean indicated if the templates are part of an existing module or a standalone. Defaults to
false.
- If the value is
false, the module will look likeangular.module('app'), meaningappmodule is retrieved. - If the value is
true, the module will look likeangular.module('app', []), meaningappmodule is created.
usemin
Path to
<!-- build:js [path/to/output.js] -->usemin target
This should be the output path of the compiled JS indicated in your HTML,
such as path/to/output.js shown here.
Example
ngTranslateCache: {
options: {
module: "app",
usemin: "scripts/scripts.js"
},
app: {
cwd: "app",
src: "languages/**/*.json",
dest: "build/translateCache.js"
}
}Contributing
Feel free to contribute to this repository by making pull requests to http://github.com/p3ol/grunt-angular-translate-cache and create any related issue on the same github repository.
License
Copyright (c) 2017 Ugo Stephant. Licensed under MIT license.