Comments (2)
This works as intended. You have declaration of the same id 2 times, so depending on which one came first taking precedence on others.
What you really want is to separate "definition" and "usage" of messages. Because right now extractor treat both your usages as "definition"
// here is definition
msg({ id: 'error.message', message: 'Error message' });
// here is the usage
const test = i18n._({ id: 'error.message' });
To stop the extractor
treat your second expression as the definition you need:
// pass a variable
const messageId = 'error.message'; // this can came from backend response, or from other file when defined with `msg`
i18n._(messageId);
// or eplicitly ignore extracting from here:
/* lingui-extract-ignore */
i18n._('error.message' );
That's also a better strategy for translating BE messages:
// definition
const authErrors = {
'not_logged': msg`You are not logged`,
'user_not_exist': msg`No such user`,
}
// usage
const test = i18n._(authErrors[response.error.code]);
from js-lingui.
Ok, thank you, will use this strategy.
from js-lingui.
Related Issues (20)
- Double Render caused by wrong assertion HOT 1
- [Vite] Parentheses in catalog pathnames causes them to be unrecognized HOT 1
- Double render due to wrong assertion on nextjs-babel example HOT 1
- Using Trans inside a Plural macro unexpectedly replaces "#" found in variables HOT 5
- Webpack warning lingui-loader with pnpm HOT 2
- Examples show useEffect deps warning HOT 1
- Cannot kill git pre-commit hook while lingui command is running HOT 4
- Provide some way to turn off newline collapsing HOT 2
- `unraw` default export resolution error in React Native 0.73.2 HOT 1
- Dynamic loading not working with Expo HOT 1
- Support check the translated `msgstr` as expected HOT 2
- Lingui doesn't extract msg within a msg HOT 2
- lingui extract-experimental empty space after {} HOT 2
- Error when aliasing Trans from '@lingui/react' in presence of macro Trans from '@lingui/macro' HOT 2
- `Nextjs` `swc` plugin example not working HOT 3
- Macro: t inside t causing ReferenceError: t is not defined HOT 3
- why not working plural macro? please help me...
- Improve React syntax with useLingui HOT 13
- [SIMPLE PATCH READY] Simple hack for compatibility with Turbopack (NextJS) HOT 2
- Missing auto-generated `id` for `<Trans>` macro when using Typescript HOT 4
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.