ngx-translate-po-http-loader icon indicating copy to clipboard operation
ngx-translate-po-http-loader copied to clipboard

Error in gettext-parser after angular 6 upgrade

Open DenderMen opened this issue 6 years ago • 20 comments

After upgrading to Angular 6 and RXJS 6 I receive the following error after ng serve

ERROR in ./node_modules/@biesbjerg/ngx-translate-po-http-loader/node_modules/gettext-parser/lib/poparser.js Module not found: Error: Can't resolve 'stream' in '../node_modules/@biesbjerg/ngx-translate-po-http-loader/node_modules/gettext-parser/lib'

DenderMen avatar May 08 '18 09:05 DenderMen

Error appears because of breaking changes in cli v6. They removed node shimming.

maciejlutostanski avatar May 09 '18 05:05 maciejlutostanski

@biesbjerg please update to the latest versions of angular and rxjs

Mallfurion avatar May 11 '18 09:05 Mallfurion

Sorry, I simply don’t have the time at the moment. You are welcome to submit a PR.

biesbjerg avatar May 11 '18 11:05 biesbjerg

This workaround worked for me :

  • https://github.com/angular/angular-cli/issues/10681#issuecomment-389160125
  • https://gist.github.com/niespodd/1fa82da6f8c901d1c33d2fcbb762947d

enavarro222 avatar May 16 '18 12:05 enavarro222

@enavarro222 worked for me, thank you !

DarthPinguin avatar May 23 '18 14:05 DarthPinguin

@enavarro222: instead of patching node modules in a post-install script, @rezonant suggests here to use tslint patch.

Create an empty operator in file src/noop.js:

// ngx-translate-po-http-loader hack: replace missing node modules by an empty operator
// @see https://github.com/biesbjerg/ngx-translate-po-http-loader/issues/22
export const NOOP = 0; 

Then update your tsconfig.json to use it instead of "sream" module:

{
    "compilerOptions": {
        "paths": {
            "stream": [
                "noop"
            ]
        }
    }
}

update:

Build is ok now, but I get the following error on runtime:

TypeError: superCtor is undefined[En savoir plus]
inherits_browser.js:5
./node_modules/gettext-parser/lib/poparser.js:446
...

@see the original PR used as example: https://github.com/Chocobozzz/PeerTube/pull/742/files

Toub avatar Jul 04 '18 11:07 Toub

As this module requires gettext-parser which requires node itself, I end up by converting the po file to json using node before building the application (each time my po file is updated).

The json is now integrated to my app and can be loaded using the simple http loader: https://github.com/ngx-translate/http-loader

To ensure compatibility, the conversion is based on ngx-translate-po-http-loader itself:

var path = require('path');
var fs = require('fs');
var gettext = require('gettext-parser');

let i18nBaseDir = path.join(__dirname, '../../../..', 'src/assets/i18n');
console.log(`Scan po files into "${i18nBaseDir}"`)

let poFiles = fs.readdirSync(i18nBaseDir).filter(function (elm) { return elm.match(/.*\.po/ig); });

poFiles.forEach(poFileName => {
  convertPoToJson(i18nBaseDir, poFileName);
});

function convertPoToJson(i18nBaseDir, poFileName) {

  var poFilePath = path.join(i18nBaseDir, poFileName);
  console.log(`Process po file "${poFilePath}"`);

  var poData = fs.readFileSync(poFilePath, 'utf8');

  const translations = {};

  const po = gettext.po.parse(poData, 'utf-8');

  if (!po.translations.hasOwnProperty('')) {
    return translations;
  }

  Object.keys(po.translations[''])
    .forEach(key => {
      const translation = po.translations[''][key].msgstr.pop();
      if (key.length > 0 && translation.length > 0) {
        translations[key] = translation;
      }
    });

  let jsonFilePath = path.join(i18nBaseDir, poFileName.replace(/\.[^/.]+$/, '') + '.json');

  console.log(`Generate json file "${jsonFilePath}"`);
  fs.writeFileSync(jsonFilePath, JSON.stringify(translations));
}
node scripts/dev/i18n/lib/i18n-po-to-json.js

Toub avatar Jul 04 '18 14:07 Toub

Does it means that I can't use to files in my spare app served by nginx ?

vtolstov avatar Sep 10 '18 08:09 vtolstov

It looks like the problem is coming from gettext-parser, so is not directly related to this package. Somebody has proposed a gettext-parser pull request . Try it. https://github.com/smhg/gettext-parser/pulls

sancelot avatar Oct 26 '18 11:10 sancelot

@biesbjerg I created a new PR like you proposed :)

RignonNoel avatar Dec 07 '18 15:12 RignonNoel

@RignonNoel is this the PR that addresses this issue?

A related concern. This library seems a bit abandoned and people are still using it. What shall we do about it?

sergiojoker11 avatar Dec 13 '18 12:12 sergiojoker11

Agreed. I just installed it then checked the issues, and now I'm uninstalling it without ever getting started.

bluebaroncanada avatar Dec 13 '18 15:12 bluebaroncanada

Agreed. I just installed it then checked the issues, and now I'm uninstalling it without ever getting started.

@bluebaroncanada It doesn't mean the library doesn't do its job -it actually does. My comment was more about 'what do we do to keep this chunk of SW alive?'

sergiojoker11 avatar Dec 13 '18 16:12 sergiojoker11

@sergiojoker11 Yes, it's this PR #26. I wait for an approval of @biesbjerg.

The gettext-parser library is not abandonned but yes people doesn't have lot of time to invest in it (like this one apparently).

It's always the same things, you have multiple choice :

  • You create sone PRs and help peoples maintain their packages
  • You speak with mainteners to check if you can become an official developer (if you want and have time for it)
  • You fork it and do a better job than actual mainteners to keep it alive (if mainteners is definitly dead)
  • You find and use another package

For this package i'm on phase 1, but since i need it and i don't have an answer it's possible that i propose an official support for a fork of this package if it continue.

RignonNoel avatar Dec 13 '18 22:12 RignonNoel

Since @biesbjerg didn't answer in the last 6 month despite the fact we have a fix since 2 month i created a fork of the project here : https://www.npmjs.com/package/@fjnr/ngx-translate-po-http-loader

My company will support officially the package, so feel free to redirect your issues on this new fork if you have some in waiting.

RignonNoel avatar Jan 07 '19 22:01 RignonNoel

Thanks a lot @RignonNoel, you should create a PR on https://github.com/ngx-translate/core#plugins to change the plugins link to point to your fork.

dsnoeck avatar Jan 22 '19 09:01 dsnoeck

Couldn't immediately find the link to the github repo for the fork, so for others reading the thread above, it might be interesting to know as well that the fork lives here: https://github.com/FJNR-inc/ngx-translate-po-http-loader

bram-atmire avatar Apr 07 '19 13:04 bram-atmire

Thanks to all, but i tested all provided solutions and still not working for me!

imoaka avatar Jun 25 '19 08:06 imoaka

Thanks to all, but i tested all provided solutions and still not working for me!

Can you be more precise ? Do you have a specific error ?

RignonNoel avatar Jun 25 '19 20:06 RignonNoel

Thanks to all, but i tested all provided solutions and still not working for me!

Can you be more precise ? Do you have a specific error ?

@RignonNoel No, it's the same! Finally, This worked for me : https://gist.github.com/niespodd/1fa82da6f8c901d1c33d2fcbb762947d Thanks a lot.

imoaka avatar Jun 27 '19 13:06 imoaka