lukasgeiter/gettext-extractor

Can't extract comments from some situations

Closed this issue · 2 comments

mappu commented

Hi, thanks for this project -

I have some situations where comments are not properly extracted. I don't have an exact test case, but it's something like:

  1. multiple map key assignments
var x = {
   "foo": translate("foo"), /// TRANSLATORS: description of foo
   "bar": translate("bar"), /// TRANSLATORS: description of bar
   "baz": translate("baz"), /// TRANSLATORS: description of baz
}

In this case only the first comment would be extracted and matched.

  1. Some long concatenation
var x = "foo" +
   /// TRANSLATORS: comments for bar
   translate("bar") + 
   /// TRANSLATORS: comments for baz
   translate("baz") +
   "foo"
;

In this case none of the comments are extracted and matched.

I read the discussion in #4 (comment) so I guess these constructs have some different representation in the AST that is not understood.

In my codebase I can work around this by extracting to a local variable first before building the longer construct. The comments can be extracted in this way, but, it's less clear.

Thanks for reporting this issue. I'll try to fix this in the next release.

I've just published version 3.5.2 which should resolve the first issue.

As for the second example, this should already be working. However, you'll have to explicitly enable the extraction of comments on the previous line with otherLineLeading:

JsExtractors.callExpression('...', {
    arguments: { ... },
    comments: {
        otherLineLeading: true,
        sameLineLeading: true,
        sameLineTrailing: true
    }
})