adesisnetlife / grunt-pug-i18n Goto Github PK
View Code? Open in Web Editor NEWCompile Pug/Jade templates with internationalization support based on JS/JSON/YAML files using Grunt
License: MIT License
Compile Pug/Jade templates with internationalization support based on JS/JSON/YAML files using Grunt
License: MIT License
I use Grunt, Jade and express.js.
In my jade template i Use i18n - https://github.com/mashpie/i18n-node/
like this:
span #{__('agency')}
When i start grunt serve it is ok, it works excellent. But if i want to compile it grunt-jade tell me that
span #{__('agency')}
undefined is not a function
Could you tell me how in grunt-jade i could define internationalization like this:
#{__('agency')}
not like:
#{$i18n.agency}
Because i18n in express js define it in different way.
I switched to grunt-jade-i18n from grunt-contrib-jade and I have now an infinite loop.
It is working correctly if I run grunt jade:html
It was working correctly with grunt-contrib-jade.
But an infinite loop is now present if the jade task is run from another task.
the following rule in my Gruntfile.js (simplified):
grunt.registerTask('build', function (target) {
if (target === 'dev') {
return grunt.task.run([
'jshint',
'replace:dev',
'compass:dev',
'jade:html'
]);
}
...
});
grunt.registerTask('rebuild_all', function (target) {
if (target === 'jade') {
return grunt.task.run([
'jade:html',
'copy'
]);
}
grunt.task.run([
'build:dev',
'build:prod'
]);
});
The output on the console when I'm running grunt rebuild_all:jade
is the following:
Running "rebuild_all:jade" (rebuild_all) task
Running "jade:html" (jade) task
>> Loading locale 'en'
>> Loading locale 'fr'
>> Loading locale 'nl'
Running "rebuild_all:contrib-jade" (rebuild_all) task
Running "build:dev" (build) task
Running "jshint:gruntfile" (jshint) task
>> 1 file lint free.
Running "jshint:js" (jshint) task
>> 27 files lint free.
Running "replace:dev" (replace) task
Running "compass:dev" (compass) task
identical app/assets/css/main.css (1.72s)
identical app/assets/css/main_gui.css (1.652s)
Compilation took 3.375s
Running "jade:html" (jade) task
>> Loading locale 'en'
>> Loading locale 'fr'
>> Loading locale 'nl'
Running "rebuild_all:contrib-jade" (rebuild_all) task
Running "build:dev" (build) task
Running "jshint:gruntfile" (jshint) task
>> 1 file lint free.
Running "jshint:js" (jshint) task
>> 27 files lint free.
Running "replace:dev" (replace) task
Running "compass:dev" (compass) task
identical app/assets/css/main.css (1.707s)
identical app/assets/css/main_gui.css (1.644s)
Compilation took 3.353s
Running "jade:html" (jade) task
>> Loading locale 'en'
>> Loading locale 'fr'
>> Loading locale 'nl'
Running "rebuild_all:contrib-jade" (rebuild_all) task
Running "build:dev" (build) task
Running "jshint:gruntfile" (jshint) task
>> 1 file lint free.
Running "jshint:js" (jshint) task
>> 27 files lint free.
Running "replace:dev" (replace) task
Running "compass:dev" (compass) task
...
If I run grunt jade
, it is working correctly:
$ grunt jade
Running "jade:html" (jade) task
>> Loading locale 'en'
>> Loading locale 'fr'
>> Loading locale 'nl'
Running "contrib-jade:html-en" (contrib-jade) task
>> 2 files created.
Running "contrib-jade:html-fr" (contrib-jade) task
>> 2 files created.
Running "contrib-jade:html-nl" (contrib-jade) task
>> 2 files created.
Done, without errors.
hi, there is a problem when you use a mixin with a parameter and the i18n option. If you try to translate a mixin parameter, the console throws an error as it can´t find the variable for the translate or the variable to use inside the mixin.
Currently locales are generated as folders but can there be an option to set 1 language as the 'default' so that the folder directory will be like.
Running tasks: jade
Running "jade" task
Running "jade:templates" (jade) task
Verifying property jade.templates exists in config...OK
Files: src/index.jade -> out/index.html
Options: i18n={"locales":"locales/*.json","namespace":"$i18n"}, pretty
Running "contrib-jade" task
>> No "contrib-jade" targets found.
Warning: Task "contrib-jade" failed. Use --force to continue.
Aborted due to warnings.
Happens when running 'grunt jade' with the default settings as per the example.
It appears Jade has been renamed to pug (re: pugjs/pug#2184) as well as grunt-jade-i18n (now https://github.com/gruntjs/grunt-contrib-pug). Makes sense to keep up-to-date I'd think!
it would be really nice to have locale name available.
I have data configured through yaml file and I pass this data to template. i.e.:
item:
en:
title: some title
es:
title: algún título
so in template I'd like to use something like this:
data[$i18n.localeName].title
It could be done by adding one line to i18n.coffee file at line 49:
opts.data[namespace].localeName = locale
https://github.com/AdesisNetlife/grunt-jade-i18n/blob/master/tasks/i18n.coffee#L140
should be
grunt.fail.warn
I'm building an Angular app with Yeoman help. Managed to introduce jade for compilation, but when trying to include grunt-jade-i18n I'm getting the following output:
Running "jade:dev" (jade) task
>> Loading locale 'es_ES'
Warning: Object #<Object> has no method 'warm' Use --force to continue.
My jade task is the next one:
jade: {
dev: {
options: {
pretty: true,
i18n: {
locales: 'locales/*.json',
namespace: '$i'
}
},
files: [{
cwd: '<%= yeoman.app %>',
src: '**/*.jade',
dest: '.tmp',
expand: true,
ext: '.html'
}]
},
build: {
options: {
i18n: {
locales: 'locales/*.json',
namespace: '$i'
}
},
files: [{
cwd: '<%= yeoman.app %>',
src: '**/*.jade',
dest: '.tmp',
expand: true,
ext: '.html'
}]
}
},
The only place where I can find a .warm method used is in tasks/i18n.coffee:141
Is there a way to customize a file name with specified language when distributing?
For example,
/* now */
files: {
"dist/subfolder/index.html": "www/subfolder/index.jade"
}
then files generated are "dist/subfolder/zh_CN/index.html" and "dist/subfolder/en_US/index.html", but I want it to be "dist/zh_CN/subfolder/index.html". So I need something like this:
/* wanted */
files: {
"dist/{{language}}/subfolder/index.html": "www/subfolder/index.jade"
}
So {{language}}
will be filled with "zh_CN" and "en_US" during different distributes.
Can I use grunt-jade-i18n to compile Jade with "client: true"?
The integration with grunt-newer
seems to stymie the process of jade compiling.
If I modify locales/*.json
, task would execute and output result;
but if I modify *.jade
, the original jade-compiling task is not executed.
Cannot run native Jade task without i18n options.
It should check if the task support i18n, and the wrap it properly, otherwise run the original Jade with no changes
Hey there,
Just an error report about a tasks directory which cannot be found with latest grunt-jade-i18n.
I didn't get this error (which seems trivial BTW, since it doesn't affect further actions) with previous versions of grunt-jade-i18n.
Here's the log:
>> Tasks directory "/Users/valerian/Documents/Web/plugins.singulia.com/groupchat/node_modules/grunt-jade-i18n/node_modules/grunt-contrib-jade/tasks" not found.
I can't make this work with a task files system like this : https://github.com/chriscoyier/My-Grunt-Boilerplate/blob/master/Gruntfile.js
It can't find the grunt-contrib-jade and grunt-newer tasks and it seems to ignore the differences between the JSON locales files.
There is an issue while Grunt tries to load the grunt-contrib-jade from the first level node dependencies directory.
Needs to check it in higher levels and if the task was not found, fall back to inner package installed dependencies.
Also thanks to @felixzapata
I'm having trouble running this module:
$ grunt
Running "jade:templates" (jade) task
Warning: Cannot call method 'split' of undefined Use --force to continue.
Aborted due to warnings.
I even copy pasted the documentation examples to try to get it to work:
Gruntfile.js:
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
jade: {
templates: {
options: {
// jade i18n specific options
i18n: {
locales: 'locales/*.json',
namespace: '$i18n'
},
// Jade specific options
pretty: true
},
files: {
"public/index.html": ["views/index.jade"]
}
}
}
});
// Load plugins for the tasks.
grunt.loadNpmTasks('grunt-jade-i18n');
// Default task(s).
grunt.registerTask('default', ['jade']);
};
locales/es_ES.json:
{
"hello": {
"world": "Hola Mundo"
}
}
views/index.jade:
body
h1 #{$i18n.hello.world}!
p Using locale #{$localeName}
But I'm still getting that error. Here's my grunt version info:
$ grunt --version
grunt-cli v0.1.13
grunt v0.4.5
I'm using "grunt-jade-i18n": "~0.3.2"
as a devDependency in package.json, and doing grunt --force
doesn't help.
It may be more common to append the locale as the prefix. Such as
dest/en_US/path/to/file.html
other than
dest/path/to/en_US/file.html
At least one config option is welcomed!
THX so much~
Hello,
Thanks for the great work first :)
After upgrading my stack to NPM v3.3.x (this is probably a general issue of NPM v3.x branch), grunt-jade-i18n stopped compiling my files because of:
>> Tasks directory "/Users/valerian/Documents/Web/xxxxxx/node_modules/grunt-jade-i18n/node_modules/grunt-contrib-jade/tasks" not found.
>> Cannot rename missing "jade" task.
I was first thinking it could be due to the fact I was still using NodeJS v0.10.x, paired w/ the latest NPM version. I upgraded to NodeJS v4.x, and things didn't get better.
Looks like this is the only Grunt contrib plugin that fails on this recent build stack, others (on the many) I'm using are still passing.
Hi, there is a difference with the load of grunt-contrib-jade module between versions 0.1.3 and 0.1.4
v. 0.1.3
grunt.loadTasks path.resolve require.resolve('grunt-contrib-jade'), '../', 'tasks'
v. 0.1.4
grunt.loadNpmTasks 'grunt-contrib-jade'
This change throws an error because the module grunt-contrib-jade isn´t found.
Thanks.
I'm not sure if this is an issue, or if I'm doing it wrong. Does this program support compiling multiple pages? If I do:
files: {
"public/index.html": ["views/*.jade", "views/about/*.jade"]
}
the source jade files get merged into the same html file, instead of separate html files in separate directories:
$ tree -I node_modules
.
├── Gruntfile.js
├── locales
│ ├── en.json
│ └── es.json
├── package.json
├── public
│ ├── en
│ │ └── index.html
│ └── es
│ └── index.html
└── views
├── about
│ └── index.jade
└── index.jade
Alternatively, if I do:
files: {
"public/index.html": ["views/*.jade"],
"public/about/index.html": ["views/about/*.jade"]
}
the trees get split:
$ tree -I node_modules
.
├── Gruntfile.js
├── locales
│ ├── en.json
│ └── es.json
├── package.json
├── public
│ ├── about
│ │ ├── en
│ │ │ └── index.html
│ │ └── es
│ │ └── index.html
│ ├── en
│ │ └── index.html
│ └── es
│ └── index.html
└── views
├── about
│ └── index.jade
└── index.jade
I can see why those didn't work, but I haven't found a way to get the result I'm looking for, which would look like:
├── Gruntfile.js
├── locales
│ ├── en.json
│ └── es.json
├── package.json
├── public
│ ├── en
│ │ ├── about
│ │ │ └── index.html
│ │ └── index.html
│ └── es
│ ├── about
│ │ └── index.html
│ └── index.html
└── views
├── about
│ └── index.jade
└── index.jade
in the end.
Hi, I´d like to compile jade templates only if language files or jade templates changes. I´ve tried to use grunt newer task.
For example, if you have a simple jade task, you can use "newer:jade" to compile. The task checks if the files have changed since the previous build. But with grunt jade i18n, if you apply newer option from your Gruntfile, it ignores.
So, I´m working a version that install "grunt newer" inside "grunt jade i18n". If the languages files have changed runs "contrib-jade". Otherwise runs "newer:contrib-jade".
This version isn´t perfect because there is problem when you run several jade subtasks.. For example, "jade:views jade:index".
Bye.
Trying to render HTML from the strings within JSON but getting errors. Is this possible?
Doing this throws an error:
div.answer= #{$i18n.faq.question1.answer}
Doing this prints the HTML like a pre tag
div.answer | #{$i18n.faq.question1.answer}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.