使用angular-gettext时,找不到本地Npm模块“grunt-angular-gettext”错误

时间:2014-03-07 11:38:51

标签: angularjs gruntjs translation angular-translate

我想使用angular-gettext在我的应用上实现i18n,我跟着这个http://lostechies.com/gabrielschenker/2014/02/11/angularjspart-12-multi-language-support/ 我使用了这个命令:

  npm install -g grunt-cli
  npm install grunt
  npm install grunt-angular-gettext

我的Gruntfile.js:

 module.exports=function(grunt){
grunt.loadNpmTasks('grunt-angular-gettext');
//This task will parse all our source files and extract the texts we want to have translated – the ones that have an associated translate directive – and add them to a so called pot file.
grunt.initConfig({
    nggettext_extract:{ //we define the task name we want to configure or initialize
        pot:{
            files:{
                'po/template.pot':['../templates/*.html'] //we want the task to parse all html files in the current directory or any sub directory of it and output the result of the task into a file called template.pot
            }
        }
    },
    nggettext_compile:{
        all:{
            files:{
            'translations.js':['po/*.po'] //we want this task to load all po files in the subfolder po of the current directory and compile them into a resulting file translations.js located in the current directory.
            }
        }
        }
});

  }

当我使用这个命令grunt nggettext_extract来提取翻译时我有这个错误:

  >> Local Npm module "grunt-angular-gettext" not found. Is it installed?
   Warning: Task "nggettext_extract" not found. Use --force to continue.

   Aborted due to warnings.

我不知道为什么?包grunt-angular-gettext存在于节点模块中 你能帮我解决这个问题吗?

3 个答案:

答案 0 :(得分:4)

尝试在项目文件夹中运行:

npm install grunt-angular-gettext --save-dev

我有一个类似的问题,运行上面的命令为我做了伎俩

答案 1 :(得分:1)

我不知道这是否会对你有所帮助,但是我得到了同样的错误,经过一段时间的调查,我意识到我在grunt.initConfig中的nggettext_extract条目不正确,我在错误的级别(我不小心将它放在shell中),我发现这不是你的问题,但它可能仍然是Gruntfile中的东西。

答案 2 :(得分:1)

解决方案是首先确保目录中有一个package.json文件。

运行:  npm init 然后  npm install grunt  npm install grunt-angular-gettext

这将安装实际模块。 有关此主题的更多信息,请参阅:https://github.com/gruntjs/grunt/issues/232