i18n-webpack-plugin icon indicating copy to clipboard operation
i18n-webpack-plugin copied to clipboard

Plugin doesn't work with [email protected]

Open ma2ciek opened this issue 7 years ago • 9 comments

I'm using [email protected] and wanted to take a look at this plugin while working on the https://github.com/ckeditor/ckeditor5/issues/387, but I got into few troubles.

compiler.parser.plugin is deprecated now. So I changed this line into something like this:

compiler.plugin("compilation", function(compilation, params) {
  params.normalModuleFactory.plugin("parser", (parser, options) => {
    parser.plugin("call " + functionName, (expr) => {
       console.log("it works");
    });
  });
});

But unfortunately it seems to be not working now... Could you provide some info how to fix it?

Regards, Maciek

ma2ciek avatar Feb 01 '17 16:02 ma2ciek

Although it has warning in webpack 2.2.0, but is still worked in my project.

codelegant avatar Feb 06 '17 03:02 codelegant

It turned out that the bug (or feature) was somewhere else.

Webpack parser runs "call fn" callback only when fn is not defined in the code (I'm not sure why). So when I have

const t = this.t;
t()

the parser doesn't see t invocation.

I have to use t() function later to provide multi-language support and to be able to transform this string later based on that string and additional words (translated string is used as a template).

ma2ciek avatar Feb 06 '17 13:02 ma2ciek

I'm with this problem too

rafaelmaruta avatar Mar 21 '17 18:03 rafaelmaruta

Either do I, anyone knows how to fix it?

josemigg avatar Mar 23 '17 15:03 josemigg

I had to use acorn to be able to create translation service https://github.com/ckeditor/ckeditor5-dev/blob/master/packages/ckeditor5-dev-utils/lib/translations/translationservice.js, but it would be much nicer if the webpack could handle it by itself.

ma2ciek avatar Mar 23 '17 16:03 ma2ciek

@ma2ciek @d3viant0ne noticed it had been a couple weeks since this was last commented on, was hoping to see if there was some kind of resolution? Thanks for the help!

timothylombrana avatar Apr 25 '17 16:04 timothylombrana

I had to implement my own solution with usage of the Acorn parser,

ma2ciek avatar Apr 28 '17 20:04 ma2ciek

@alphapilgrim - There is a 1.0.0-beta.0 build on npm that will solve that particular issue. Keep in mind there is going to be churn on that beta dist-tag for a few weeks.

joshwiens avatar May 01 '17 23:05 joshwiens

Webpack parser runs "call fn" callback only when fn is not defined in the code (I'm not sure why).

@ma2ciek looks like it's a current implementation of the webpack's Parser. See: https://github.com/webpack/webpack/blob/master/lib/Parser.js#L257 https://github.com/webpack/webpack/blob/master/lib/Parser.js#L1100

I'm not sure why you want to replace the calls of defined functions, but looks like to affect them you have to register another callback for the evaluate defined Identifier ${functionName} event and return an evaluated expression (instance of BasicEvaluatedExpression).

Smthing like this:

const BasicEvaluatedExpression = require('webpack/lib/BasicEvaluatedExpression');
// ...
parser.plugin(`evaluate defined Identifier ${name}`, function (expr) {
  return new BasicEvaluatedExpression().setIdentifier(expr.name).setRange(expr.range);
});

sullenor avatar Aug 03 '17 19:08 sullenor