lingui / js-lingui

🌍 📖 A readable, automated, and optimized (3 kb) internationalization for JavaScript

Home Page:https://lingui.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Malformed extracted words when '\n' is a variable inside a template literal

JSteunou opened this issue · comments

Describe the bug

Extracted template literal containing ${'\n'} lead to malformed string that break JS modules after build

This is a regression from v2. I see this issue while migrating a project from v2 to v3

To Reproduce
Steps to reproduce the behavior, possibly with minimal code sample, e.g:

import {t} from "@lingui/macro"

export default function App() {
   return <img alt={t`foo${'\n'}bar`} src="" />
}

in po you will see

msgid ""
"foo{\n"
"}bar"
msgstr ""

Expected behavior
A clear and concise description of what you expected to happen.

msgid "foo{0}bar"
msgstr ""

Workaround

import {t} from "@lingui/macro"

const LB = '\n'

export default function App() {
   return <img alt={t`foo${LB}bar`} src="" />
}

Additional context
Add any other context about the problem here.

  • jsLingui version lingui --version 3.11.1
  • Babel version npm list @babel/core 7.14
  • Your Babel config (e.g. .babelrc) or framework you use (Create React App, Meteor, etc.)
commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

will check with latest version but did not see any related fix

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

did not check, forgot to test, will do asap

We didn't work on it yet mate, there isn't enough bandwidth from my side to tackle all the issues. Any contribution it's welcome

The issue is still here indeed, I played with it a little and I think I got the logic behind it. Since v3, placeholders are named when they can be named, but if using direct string like t`This is ${'completely'} silly` it will be extracted as This is {completely} silly because completely is the name of the variable and this come with this handy feature in v3.

But, in the AST this is a Literal with value whereas a variable or constant is an Identifier with a name so maybe there is a way to filter this.

To be continued... :)

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@semoal could you re-open it please, this is still an ongoing issue :)