You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When using lazy as described here, if the defineMessage function is located after the usage of i18n._ in the file system, then lingui extract will use the id of the message in the msgstr instead of the actual message.
Since we are using --overwrite for our extract, this means the string in the source locale is not translated properly.
It was working fine before in v3 using t instead of msg
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 definitionmsg({id: 'error.message',message: 'Error message'});// here is the usageconsttest=i18n._({id: 'error.message'});
To stop the extractor treat your second expression as the definition you need:
// pass a variableconstmessageId='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:
// definitionconstauthErrors={'not_logged': msg`You are not logged`,'user_not_exist': msg`No such user`,}// usageconsttest=i18n._(authErrors[response.error.code]);
Describe the bug
When using lazy as described here, if the
defineMessage
function is located after the usage ofi18n._
in the file system, thenlingui extract
will use the id of the message in themsgstr
instead of the actual message.Since we are using
--overwrite
for our extract, this means the string in the source locale is not translated properly.It was working fine before in v3 using
t
instead ofmsg
To Reproduce
File 1: define the messages
File 2: use the messages
If file 1 is found before file 2 in the file system, then running
extract
results in the following po file:Video:
CleanShot.2023-11-15.at.10.42.54.mp4
Full repro here: https://github.com/MPeloquin/LinguiV4ExtractIssue (with v3 version working)
Expected behavior
I would expect the PO file to always look like
No matter how I structure my files.
Additional context
This is a pattern we use a lot to translated ids coming from the BE
lingui --version
4.5.0npm list @babel/core
7.23.3@lingui/swc-plugin
babel-macro-plugin
.babelrc
) or framework you use (Create React App, NextJs, Vite) ViteThe text was updated successfully, but these errors were encountered: