ngx-translate-po-http-loader
ngx-translate-po-http-loader copied to clipboard
Error in gettext-parser after angular 6 upgrade
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'
Error appears because of breaking changes in cli v6. They removed node shimming.
@biesbjerg please update to the latest versions of angular and rxjs
Sorry, I simply don’t have the time at the moment. You are welcome to submit a PR.
This workaround worked for me :
- https://github.com/angular/angular-cli/issues/10681#issuecomment-389160125
- https://gist.github.com/niespodd/1fa82da6f8c901d1c33d2fcbb762947d
@enavarro222 worked for me, thank you !
@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
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
Does it means that I can't use to files in my spare app served by nginx ?
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
@biesbjerg I created a new PR like you proposed :)
@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?
Agreed. I just installed it then checked the issues, and now I'm uninstalling it without ever getting started.
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 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.
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.
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.
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
Thanks to all, but i tested all provided solutions and still not working for me!
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 ?
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.