Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

grunt-i18n-templates

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-i18n-templates - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

6

package.json
{
"name": "grunt-i18n-templates",
"description": "i18n for front-end templates.",
"version": "0.1.0",
"version": "0.1.1",
"homepage": "https://github.com/M-jerez/i18nTemplates",

@@ -47,4 +47,6 @@ "author": {

"ejs",
"html"
"html",
"grunt",
"grunt-i18n"
]
}
# grunt-i18nTemplates
> i18n for front-end templates.
## Getting Started
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.
## features
+ Parse your templates and automatically generate the locale files.
+ Compatible with multiple template engines. the syntax used to create a locale-Definition `[[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.
+ Join all your templates in a single `html.json` file, so you can access them from javascript in a more convenient way.
+ Yuo will not loose the information edited in your locale files. You can run the task whenever you want to parse new and existent templates, any new locale-Definition will be added to locale files, but will keep all your previously translated values, your translation will stay and never been overwrited.
### Generated templates
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.
```js
{
"index":"<p>the template content .....",
"form":"<for><inpup> ......"
}
```
### Using the generated code.
i.e: using Jquery and mustache
```js
//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,{});
});
```
# Grunt and Task Configuration
This plugin requires Grunt `~0.4.5`

@@ -17,3 +52,3 @@

```js
grunt.loadNpmTasks('grunt-i18nTemplates');
grunt.loadNpmTasks('grunt-i18n-templates');
```

@@ -30,3 +65,3 @@

options: {
locales: \["en","es","de"\],
locales: ["en","es","de"],
templatesFolder: "./public/templates", //this is where the translated templates will be generated

@@ -42,7 +77,7 @@ localesFolder: "./src/locales" //this is where translation files will be stored

### Options (Required) !!IMPORTANT: if this options are not configured the system will throw an exception!!
### Options
#### options.templatesFolder
Type: `String`
Default value: `none`
Default value: `none, this value is required and not set by default.`

@@ -53,8 +88,6 @@ A path to the templates folder.

Type: `String`
Default value: `none`
Default value: `none, this value is required and not set by default.`
A path to the locales folder.
### Options
#### options.locales

@@ -64,6 +97,6 @@ Type: `Array`

An Array defining all the languages. i.e: `\["en","es","de"\]`
An Array defining all the languages. i.e: `["en","es","de"]`
### Usage Examples
This example will generate 4 locale files, one for each language, and will generate 5 templates files, one for each language plus the original one.
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).
```js

@@ -73,5 +106,5 @@ grunt.initConfig({

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
locales: ["en","es","de"],
templatesFolder: "./public/templates",
localesFolder: "./src/locales"
},

@@ -78,0 +111,0 @@ your_target: {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc