Comments (2)
Read the first note in this paragraph.
https://lingui.dev/tutorials/react-patterns#translations-outside-react-components
from js-lingui.
Here is an issue with an example itself. The app component doesn't get re-rendered since nothing changed from React's point of view.
So the solution would be splitting to root component with provider and children components to be able to use useLingui
hook and let LinguiProvider re-trigger render of components subtree
function App() {
useEffect(() => {
loadCatalog("en")
}, [])
return (
<I18nProvider i18n={i18n}>
<AppContent />
</I18nProvider>
)
}
function AppContent() {
const [count, setCount] = useState(0)
const { i18n } = useLingui()
return (
<div className="App">
<div>
<a href="https://vitejs.dev" target="_blank">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://reactjs.org" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
<a href="https://lingui.dev" target="_blank">
<img src={linguiLogo} className="logo react" alt="Lingui logo" />
</a>
</div>
<h1>Vite + React + Lingui</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
<Plural value={count} one="# month" other="# months" />
</button>
<p>
<Trans>
Edit <code>src/App.tsx</code> and save to test HMR
</Trans>
</p>
<p>
<button
style={{ marginRight: "20px" }}
onClick={() => loadCatalog("pl")}
>
Polish
</button>
<button onClick={() => loadCatalog("en")}>English</button>
</p>
</div>
<p className="read-the-docs">
<Trans>Click on the Vite and React logos to learn more</Trans>
<br />
{t(i18n)`Click on the Vite and React logos to learn more`}
{/* or */}
{i18n._(msg`Click on the Vite and React logos to learn more`)}
{/* or in >[email protected], export underscore from useLingui hook https://github.com/lingui/js-lingui/pull/1721*/}
{_(msg`Click on the Vite and React logos to learn more`)}
</p>
</div>
)
}
export default App
from js-lingui.
Related Issues (20)
- React Fragment (`<>`) inside `<Plural>` is not working HOT 5
- Impossible to use with Vite? HOT 1
- definePlural macro HOT 4
- rspack now supports wasm plugins, lingui integration example could be improved HOT 3
- Escaped curly-braces doesn't preserve in development mode HOT 1
- <Trans> breaks React JSX semantics with regards to booleans HOT 3
- Consider renaming of the macro components HOT 3
- selectOrdinal error HOT 2
- Lingui CLI extraction puts msgid as msgstr HOT 3
- i18n._(id) throws error if id param passed as undefined
- # is being replaced by%__lingui_octothorpe__% outside plural and selectordinal HOT 3
- Setup with webpack
- Order by is not alphabetically HOT 1
- Avoid flashing of the default language HOT 1
- Available~ Free v-bucks Codes in Fortnite- Free v bucks code generator 2024 June Method
- [June-Code]** Free v bucks code generator 2024-2025 Available Free Vbucks Codes in Fortnite
- {Working}++Redeem v bucks codes Available Free v bucks Code 2024
- [Code-Works!]^ Free v bucks code generator 2024 -Are There Any Available Free Vbucks Codes in Fortnite?
- Ids are displayed sometimes on production build HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from js-lingui.