简体   繁体   中英

Angular-gettext extract annotations from javascript files

With Angular-gettext we extract annotated strings from html as specified in Gruntfile.js :

grunt.initConfig({
  nggettext_extract: {
    pot: {
      files: {
        'po/template.pot': ['src/views/*.html']
      }
    },
  },
})

Is it possible to extract strings from javascript files too?

I have a case where I'm generating strings from an angularjs controller:

<textarea ng-model="generatedCSV"></textarea>

the header row of the CSV is:

"Full Name", "Email"

Which needs translating to other languages.

Is there a nice way to do this with angular-gettext?

EDIT: For future readers: read the OP's comment on this, too, as it contains helpful information.

According to the site (I've played with angular-gettext, but haven't used this feature):

http://angular-gettext.rocketeer.be/dev-guide/annotate-js/

If you have text that should be translated in your JavaScript code, wrap it with a call to a function named gettext. This module provides an injectable function to do so:

angular.module("myApp").controller("helloController", function (gettext) {
    var myString = gettext("Hello");
});

The Hello string will be added to your .pot file using the code above.

Have you tried that?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM