Extract dynamic messages without the help of i18nMark
See original GitHub issueI would like to abstract the use of <Trans />
.
e.g.
const TextButton1 = ({ children }) => (
<button>
<Trans>{children}</Trans>
</button>
);
const TextButton2 = ({ children }) => <Trans render="button">{children}</Trans>;
// used in somewhere else
<TextButton1>some message id<TextButton1>
<TextButton2>some other message id<TextButton2>
In this way, I don’t need to import Trans
in every single file that is using the button component. However, lingui extract
cannot extract properly.
I need to do
<TextButton1>{i18nMark('some message id')}<TextButton1>
<TextButton2>{i18nMark('some other message id')}<TextButton2>
if I want the extract works. However, in this way I need to import i18nMark
in every single file instead which leads to same problem that I want to avoid at first.
Any suggestion?
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
lingui/js-lingui - Gitter
I'm trying to figure what's the best API for upcoming js.macro, if we want to support messages with metadata (e.g. descriptions).
Read more >Dynamic loading of message catalogs - LinguiJS
Here's an example of a basic setup with a dynamic load of catalogs. ... string */ export async function dynamicActivate(locale: string) { const...
Read more >Angular Internationalization
The localization process includes the following actions. Extract text for translation into different languages; Format data for a specific locale. A locale ...
Read more >Pengumuman Lama - GnuCash
Bug 688917 - Help button not working when editing style sheets. ... It also provides an export format and an output file name...
Read more >FreedomBox/ReleaseNotes - Debian Wiki
container: Display help message when no args are passed; container: Show default values in ... storage: Fix enumerating partitions without mount points ...
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
@chochihim You are my kind of guy. I am also rather lazy writing these things all over the place… but I don’t think there is an easy way to solve this. Also, you are mixing two things together. If you use
<Trans>
then you don’t need to worry abouti18nMark
at all.I am afraid your idea is probably impossible simply because extractor can only statically analyze the code and what you have here is some runtime code that needs to be executed first and it would not really work.
Just for your information, there is a new and hot release with macros. Personally, It won’t help with this use case, but it’s a little bit nicer.
Edit: Darn it, @tricoder42 was faster for a few seconds 😄
I understand that. I didn’t understand your intentions for the first time, but now it makes sense.
You have two options, but both require to use either
Trans
orI18n
component:First, pass
Trans
components:Second, use
I18n
render prop component (this also works if you need to pass translated messages to html attributes, like href, title, etc):It may look cumbersone to wrap all messages either in
Trans
ori18n._
, but defining messages in code is only the half of internationalization. You need to have a workflow which extracts messages to external file and loads translations.You could bypass it by passing
title
ordescription
prop directly toid
prop ofTrans
component, but then you’re on your own - you need to define message manually and keep it updated. In large projects it soon might become very error prone.