question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Macro `t` with template string id could not be extracted

See original GitHub issue

Describe the bug Macro t will NOT be extracted to message catalog, if we pass id with a template string like t({id: `id`}).

To Reproduce

import { t } from '@lingui/macro'

export default function App() {
  return (
    <div>
      <p>
        {/* id with string */}
        {t({
          id: 'today1',
          message: `Today is ${new Date()}`,
        })}
      </p>

      <p>
        {/* id with template literals */}
        {t({
          id: `today2`,
          message: `Today is ${new Date()}`,
        })}
      </p>
    </div>
  )
}

Only today1 is extracted, but today2 is missing:

{
  "today1": {
    "translation": "Today is {0}",
    "message": "Today is {0}",
    "extractedComments": []
  }
}

Expected behavior today 2 should also be extracted.

Additional context Add any other context about the problem here.

  • jsLingui version 3.4.0
  • Babel version @babel/core@7.12.10

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
semoalcommented, Apr 5, 2021

Released this feature/fix on 3.8.3 guys! Thanks to everyone and special to thanks to @sultan99 who resolved this issue!

1reaction
semoalcommented, Apr 2, 2021

I think developers should be free to use any eslint rules on their own choice. I would like to try to fix that issue, but before start doing it I would like to know, is this fix not against the philosophy of lingui maintainers or maybe some other reasons were to implement it the way it is?

The “common” behaviour is to define id like a simple string with double/single quotes, that’s why the standard implementation works. When Tom refactored the v2 codebase to v3, probably didn’t though about this use case, but is not against the philosophy of Lingui, it’s just okay, (no free time on my side, and still less on Tom side)

Feel free to take it and ping me if you need some guidance =)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I resolve Error: variable template-id 'complex type' in ...
It's a bit unusual to alias a type as value . Instead, I recommend you declare it as a static member so that...
Read more >
@lingui/macro - Reference — LinguiJS documentation
This comment tells the extract plugin that following object or string should be collected to message catalog. t¶. t¶. The most common macro...
Read more >
Language Reference — Chameleon 3.8 documentation
The Template Attribute Language Expression Syntax (TALES) standard describes expressions that supply Basics (TAL) and Macros (METAL) with data. TALES is one ...
Read more >
Template Designer Documentation - Jinja
If a variable or attribute does not exist, you will get back an undefined value ... Jinja to trim_blocks , the first newline...
Read more >
Replacing text macros - cppreference.com
The syntax of a function-like macro invocation is similar to the syntax ... If the identifier is not in functional-notation, i.e. does not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found