2014-10-02 22 views
1

我在我的angularJS項目中使用grunt和grunt-angular-gettext。
無論何時更新源文件,我都會讓grunt運行grunt任務nggettext_extract,並且每當更新「po」文件時我都會讓nggettext_compile
我想我可能只是添加任務名稱我的「grunt.task.run」任務列表中,這樣說:Grunt + angular gettext:如何提取和/或連續編譯?

... 
grunt.registerTask('serve', 'Compile then start a connect web server', function (target) { 
    grunt.task.run([ 
    'nggettext_extract', <== added task, just executed on the first run 
    'nggettext_compile', <== added task, just executed on the first run 
    'clean:server', 
    'wiredep', 
    'concurrent:server', 
    'autoprefixer', 
    'connect:livereload', 
    'watch' 
    ]); 
}); 
... 

但不幸的是這僅適用於第一個咕嚕運行,而不是事後... 我甚至可以接受我的項目中任何時候運行任何文件更改(我不確定如何指定Gruntfile.js中的依賴關係,我對它很新... :-()

如果它可以有任何幫助,這些是我的nggettext_任務配置(非常標準):

... 

    nggettext_extract: { 
     pot: { 
     files: { 
      'po/template.pot': [ 'app/**/*.html', 'app/scripts/**/*.js' ] 
     } 
     } 
    }, 

    nggettext_compile: { 
     all: { 
     files: { 
      'app/scripts/translations.js': ['po/*.po'] 
     } 
     } 
    }, 

    ... 
+0

請張貼'手錶:'你gruntfile的部分。這就是配置什麼時候運行的地方。 – 2014-10-13 18:16:35

回答

0

我認爲,類似這樣的事情在你的gruntfile應該工作:

... 
watch: { 
    po-changed: { 
    files: ["po/*.po"], 
    tasks: ["nggettext_compile"], 
    }, 
    update-pot: { 
    files: ['app/**/*.html', 'app/scripts/**/*.js'], 
    tasks: ["nggettext_extract"], 
    }, 
}, 
... 
+0

謝謝!我自己已經解決了這個問題,但你的回答是正確的。我還爲'update-pot'手錶添加了一個補充任務('tasks:['nggettext_extract','po_auto_translate']'),以運行我的腳本以自動翻譯缺失的條目,以幫助人類翻譯人員。 .. – MarcoS 2014-10-14 07:14:13