t in attribute not updating when activating language change
See original GitHub issueDescribe the bug t in attribute not updating when activating language change
To Reproduce Steps to reproduce the behavior, possibly with minimal code sample, e.g: translate.zip
import logo from "./logo.svg";
import "./App.css";
import { ThemeProvider } from "styled-components";
import {
themeBaseLight,
ButtonSmall,
ButtonLink,
} from "@cmctechnology/phoenix-stockbroking-web-design";
import { i18n } from "@lingui/core";
import { I18nProvider } from "@lingui/react";
import { messages as en } from "./locales/en/messages.js";
import { messages as pt } from "./locales/pt/messages.js";
import { Trans, t } from "@lingui/macro";
i18n.load("en", en);
i18n.load("pt", pt);
i18n.activate("en");
function App() {
return (
<I18nProvider i18n={i18n}>
<a href="#" onClick={() => i18n.activate("en")}>
en
</a>
|
<a href="#" onClick={() => i18n.activate("pt")}>
pt
</a>
<br />
<Trans>Here is a button</Trans>
<br />
<MyButton label={<Trans>I Change</Trans>} />
<MyButton label={t`I Don't`} />
</I18nProvider>
);
}
const MyButton = ({ label }) => {
return (
<button>
<span>{label}</span>
</button>
);
};
export default App;
Expected behavior I would expect t`` to change when activating language change.
Additional context Using <Trans/> in the attribute works.
- jsLingui version
lingui --version
3.8.10 - Babel version
npm list @babel/core
7.12.3 - Your Babel config (e.g.
.babelrc
) or framework you use (Create React App, Meteor, etc.) No .babelrc, straght create-react-app
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Declaring language in HTML - W3C
Instead, move the attribute containing text in a different language to another element, as shown in this example, where the a element inherits ......
Read more >jQuery's data() attribute does not update when element data ...
The short answer is: don't use jQuery .data() for dynamically set data attributes, unless you can guarantee that data attributes are always ...
Read more >AutoCAD title block attributes do not update automatically after ...
Recreate block with the the same name af original name (command BLOCK). Save drawing and check in back to Vault. Try editing properties...
Read more ><html> element must have a lang attribute | Axe Rules
Screen readers can switch between these language libraries easily, but only if the documents specify which language(s) to read and when. If the...
Read more >Okta is not updating users attributes in some applications
For example if the user's last name has been changed from Smith to Anderson in Okta, we will send the new last name...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I found the issue comparing my code to yours. Moving the I18nProvider to a higher component updated the translations as required for
t()
.Note: no useEffect is required for this to work.
In the previous code you pasted, it’s also wrong…
This causes an infinite loop because you’re not specyfing to only render on mount.
This is the correct code, and must work as expected