1

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?

Rusty Rob
  • 16,489
  • 8
  • 100
  • 116

1 Answers1

5

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?

Jesus is Lord
  • 14,971
  • 11
  • 66
  • 97
  • 1
    Thanks for the link it solved my problem. gettext('string') only marks string for translation but doesn't actually translate it. The getString method is more useful as it both marks and translates in one. var translated = gettextCatalog.getString("Hello"); Also I added gettextCatalog as a dependency to be injected & also added *.js regex to my gruntfile. – Rusty Rob Aug 19 '14 at 02:19
  • another thing to mention.. use {{translated|translate}} in your html. That way if the variable translated is set before getText has loaded your translations mapping, it can still be updated and swapped out later using the filter. – Rusty Rob Sep 25 '14 at 01:56