Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
grunt-i18n-templates
Advanced tools
Parses your template files looking for locale Definitions with the syntax [[key: text]]
, and Generates or Updates the locale files.
Then uses those values to translate ang generate a single json file containig all your templates (one file for each defined language), so you can access those templates easily from javascript.
[[key: text]]
is not used by many other javascript templates engines. The translation is done statically with grunt, so template engines work with filles already translated.html.json
file, so you can access them from javascript in a more convenient way.All you templates will be Joined in the file html.json
this file contain all your templates without translation just joined in a json file for convenient access in the case you dont want to use any translation at all.
For every one of the languages defined in the options, the task will generate an extra file with all the templates translated using the values grabbed from the locale files. i.e: if options.locales = ["en","de","oth_er"]
then the task will generate the files en_html.json , de_html.json and oth_er_html.json
all of them already translated and ready to use in javascript.
If you have two templates index.html and form.html
, the generated json will contain one entry for each of the templates, as shown in the code bellow, using the template's name as key.
{
"index":"<p>the template content .....",
"form":"<for><inpup> ......"
}
i.e: using Jquery and mustache
//this is the english template file generated by this task and contains all you templates.
var templatesFile = "./templates/en_html.json";
jQuery.getJSON(templateFile, function(data){
/* data contains all the templates */
var templates = data;
Mustache.render(templates.index,{});
});
This plugin requires Grunt ~0.4.5
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-i18nTemplates --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-i18n-templates');
In your project's Gruntfile, add a section named i18nTemplates
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
i18nTemplates: {
options: {
locales: ["en","es","de"],
templatesFolder: "./public/templates", //this is where the translated templates will be generated
localesFolder: "./src/locales" //this is where translation files will be stored
},
your_target: {
src: ['./src/templates/**/*.html']
},
},
});
Type: String
Default value: none, this value is required and not set by default.
A path to the templates folder.
Type: String
Default value: none, this value is required and not set by default.
A path to the locales folder.
Type: Array
Default value: none
An Array defining all the languages. i.e: ["en","es","de"]
This example will generate 4 locale files in the ./src/locales
folder (one for each language), and will generate 5 templates files in the ./public/templates
, (one for each language + the one without translate).
grunt.initConfig({
i18nTemplates: {
options: {
locales: ["en","es","de"],
templatesFolder: "./public/templates",
localesFolder: "./src/locales"
},
your_target: {
src: ['./src/templates/**/*.html']
},
},
});
0.1.0
first working version.
FAQs
i18n for front-end templates.
The npm package grunt-i18n-templates receives a total of 0 weekly downloads. As such, grunt-i18n-templates popularity was classified as not popular.
We found that grunt-i18n-templates demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.