GithubHelp home page GithubHelp logo

adesisnetlife / grunt-pug-i18n Goto Github PK

View Code? Open in Web Editor NEW
35.0 35.0 18.0 66 KB

Compile Pug/Jade templates with internationalization support based on JS/JSON/YAML files using Grunt

License: MIT License

CoffeeScript 95.38% HTML 4.62%

grunt-pug-i18n's People

Contributors

aberigle avatar bitdeli-chef avatar eshikerya avatar felixzapata avatar h2non avatar jose1984 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

grunt-pug-i18n's Issues

Grunt-jade, express.js and i18n

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.

Infinite loop when the jade task is run from another task

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.

parse variables inside mixins parameters

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.

Option to set English in the default folder

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.

  • index.html <-- english
  • /es_ES/ <-- spanish
    • index.html

Warning: Task "contrib-jade" failed

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.

locale name in jade template

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

'warm' method somewhere

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

Customized file name with lang when distributing

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.

client: true

Can I use grunt-jade-i18n to compile Jade with "client: true"?

Feels like integration with grunt-newer is unnecessary

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.

Tasks directory not found

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.

Warning: Cannot call method 'split' of undefined Use

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.

NPM v3.x: "Cannot rename missing "jade" task."

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.

Failed load grunt-contrib-jade with version 0.1.4

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.

Compiling multiple web pages

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.

Use with grunt newer task

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.

HTML strings in JSON

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}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.