Search code examples
javascriptangularjstranslationgettextpo

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?


Solution

  • 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?