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.

date macro not working when used inside t macro

See original GitHub issue

Describe the bug I have a message with a date that I need to translate outside of the React component, so based on https://lingui.js.org/ref/macro.html#jsmacro-t I tried using i18n._(tToday is ${date(name)}), but it’s not working. I am getting Danas je [object Object] in the result.

To Reproduce

  1. Create react app with Create React App.
  2. Add lingui-js and set it up so you can use translations outside the components as described here: https://lingui.js.org/tutorials/react-patterns.html#translations-outside-react-components
  3. outside of the React component do:
import { date } from '@lingui/macro';
import { i18n } from './i18n';
...
const today = new Date();
const msg = i18n._(t`Today is ${date(today)}`);

then render msg in the component:

{msg}

Sandbox example - https://codesandbox.io/s/linguijs-playground-5gk1u

Expected behavior Date should be normally localized.

Additional context

  • jsLingui version 2.8.3
  • I am using React app generated with Create React App

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
igorDolzhcommented, Mar 11, 2020

You could import t before number or date (It is a hack) I made a fix for this https://github.com/lingui/js-lingui/pull/621

0reactions
tricoder42commented, Apr 13, 2020

Hey guys, please use i18n.number and i18n.date instead of macros. date and number macros were removed in v3. That should solve your issue. The other half (#621) is solved as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

find date macro not working
Ityped in t todays date in a cell in the range of the macro and copied the macro to it's new module. Didn't...
Read more >
Macro problem with Excel - Date format
Hi, I've have this code, below, which inserts today's date in a cell from a text box, but it shows the date as...
Read more >
VBA: Simple Date Macro that does not work
I've used the AutoFilter Method to show/hide the dates based upon your startdate and enddate vars. Sub hide_dates() Dim ws2 As Worksheet, ...
Read more >
Solved: Date macro variable not resolving in proc sql
The problem is that your macro variable contains a text string with year, month and date, while your input data contains a sas...
Read more >
Is anyone else experiencing a bug in the date macro?
I'm experiencing an issue where when I use the date macro and the date is wrong for "yesterday" and "today." It is very...
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