Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in gettext-parser after angular 6 upgrade #22

Open
DenderMen opened this issue May 8, 2018 · 20 comments
Open

Error in gettext-parser after angular 6 upgrade #22

DenderMen opened this issue May 8, 2018 · 20 comments

Comments

@DenderMen
Copy link

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'

@maciejlutostanski
Copy link

maciejlutostanski commented May 9, 2018

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

@Mallfurion
Copy link

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

@biesbjerg
Copy link
Owner

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

@enavarro222
Copy link

This workaround worked for me :

@DarthPinguin
Copy link

@enavarro222 worked for me, thank you !

@Toub
Copy link

Toub commented Jul 4, 2018

@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
Copy link

Toub commented Jul 4, 2018

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

@vtolstov
Copy link

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

@sancelot
Copy link

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

@RignonNoel
Copy link

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

@sergiojoker11
Copy link

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

@bluebaroncanada
Copy link

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

@sergiojoker11
Copy link

sergiojoker11 commented Dec 13, 2018

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

@RignonNoel
Copy link

RignonNoel commented Dec 13, 2018

@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
Copy link

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.

@dsnoeck
Copy link

dsnoeck commented Jan 22, 2019

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.

@bram-atmire
Copy link

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

@imoaka
Copy link

imoaka commented Jun 25, 2019

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

@RignonNoel
Copy link

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 ?

@imoaka
Copy link

imoaka commented Jun 27, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests