Js-lingui: Fix handling multiple origins

Created on 26 Aug 2018  路  8Comments  路  Source: lingui/js-lingui

Describe the bug
When editing PO catalog in some tool that adds it's own comments and then running extract again, these comments are lost and furthermore, some of them end up badly formatted and make an invalid PO file.

#: src/segments/login/organisms/PasswordLoginForm.tsx:25
#: loco:5b7d94e07ec8ae083b2dae02
msgid "username"
msgstr "username"

After extracting that comment is lost. Furthermore, for obsolete translation, it ends up like this.

#: src/segments/login/organisms/PasswordLoginForm.tsx:24
loco:5b7d94e07ec8ae083b2dae01
#, obsolete
msgid "login.validation.username-missing"
msgstr ""

Expected behavior
To keep any custom comments intact and do not break when obsolete translation is encountered.

Additional context

  • jsLingui version: 2.5.0
馃悶bug 馃摝 cli

Most helpful comment

Well, if I wanted to keep source file origins on single line (#: src/App.js:4, src/Component.js:2, then it would be complicated, but I think it's not a big deal if each reference is on separate line... So, I didn't come up with a solution to complex problem, I just simplified the problem ;)

All 8 comments

Ok, nevermind. This is actually an issue in the format produced by the service. I wasn't aware there is some difference in a notation of leading #: vs #. I suppose I will have to handle that as part of the workflow process when communicating with that service. I doubt they will change this.

On the other hand, Lingui should at least handle line breaks there so it doesn't break the whole file. Probably the best course action is to put anything after line break as separate comments prefixed with #.

Could you please explain again, how the files looks before/after running lingui extract? I mean only broken cases.

I believe this might be related to gettext-parser, so this could be fixed as part of #288.

PO File reference.

No, it's not related to #288 because it's parsed correctly based on the reference. Before and after examples are in the first comment, that's still the same. Problem is, that parser sees double #: and joins it together with a line break. Then the result is as shown above.

I got it now, thanks! I see the bug, but it's gonna be tricky to fix...

Uhh, tricky to fix you say? And you have managed to do it in last 20 minutes while talking to me on Gitter? 馃槷 馃憦 馃挴

Well, if I wanted to keep source file origins on single line (#: src/App.js:4, src/Component.js:2, then it would be complicated, but I think it's not a big deal if each reference is on separate line... So, I didn't come up with a solution to complex problem, I just simplified the problem ;)

Released in v2.6.0

Was this page helpful?
0 / 5 - 0 ratings