Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting strings from JS file with gulp-angular-gettext does not work

I use angular-gettext-tools with @gabegorelick 's gulp-angular-gettext. Everyhing is okay with html files, but I fail to extract strings from js file. I tried both gettextCatalog.getString and gettext functions - together and separately - nothing worked.

My code for extraction (smth.js file) looks like this:

  $scope.openCreateOfferPopup = function($event, buttonState) {
    $event.preventDefault();
    loadTypes();
    logger('openCreateOfferPopup');
    if (buttonState) {
      var params;
      if (!$rootScope.dashboard.spots || $rootScope.dashboard.spots.length === 0) {
        params = {
          title: 'Spots needed',
          content: gettextCatalog.getString(gettext("Oops! You need to add your spot before creating an offer!"))+
          '<br/>'+gettextCatalog.getString(gettext("Please, click on Create new spot button")),
          buttons: [{
            text: gettextCatalog.getString(gettext("Create spot")),
            href: '',
            'class': '',
            ngClick: 'openCreateSpotPopup($event)',
            ngController: 'SpotsController'
          }, {
            text: gettextCatalog.getString(gettext("cancel")),
            href: '#',
            'class': 'b-close'
          }]
        };
        DialogService.makeDialog(params, $scope);
        return;
      }

My gulp task looks like this:

import gulp from 'gulp';
import gettext from 'gulp-angular-gettext';
//import debug  from 'gulp-debug';

gulp.task('pot', function () {
    return gulp.src(['src/app/**/*.html','src/app/**/*.js',
            '!src/app/pages/static/acceptable_policy.html','!src/app/pages/static/legal.html',
        '!src/app/pages/static/privacy_policy.html','!src/app/pages/static/refund_policy.html',
        '!src/app/pages/static/terms_of_service.html'])
    //.pipe(debug({title: 'files to translate:'}))
    .pipe(gettext.extract('template.pot', {
        // options to pass to angular-gettext-tools...
    }))
    .pipe(gulp.dest('po/'));
});

I am pretty sure that js file is passed to aangular-gettext-tools - I used gulp-debug to verify it.

There are no error messages. Everything is being extracted from html, but no entries from JavaScript.

Could you point me to the source of this problem?

I have [email protected] using [email protected] and gulp 4.0.0-alpha.2

like image 747
Jehy Avatar asked Jun 17 '26 01:06

Jehy


1 Answers

Okay, I found the culprit. Angular-gettext-tools don't work with javascript ES7. We had a piece of code:

async function loadTypes() {
  if ($rootScope.dashboard.types) return;

  const { categories } = await Api.offerTypes();
  $rootScope.dashboard.types = categories;
}

And it siliently died on async function. Possibly, old version of espree package from angular-gettext-tools is to blame.

I requested compatibility with ES7 and printing some debug info (to know that files could not be translated due to some error) here: https://github.com/rubenv/angular-gettext-tools/issues/140

Right now we are going to use babel to downgrade our javascript to processable version and use it for extraction.

Update to this question from official github:

espree doesn't support it so there's probably nothing we can do. When async/await is standardized, it will be added to espree, and we should support it without any changes. Until then, use a transpiler like babel before calling angular-gettext.

like image 57
Jehy Avatar answered Jun 18 '26 14:06

Jehy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!