Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli/extract: throw when encountering same id with different defaults #200

Closed
vsnig opened this issue Apr 4, 2018 · 4 comments
Closed

cli/extract: throw when encountering same id with different defaults #200

vsnig opened this issue Apr 4, 2018 · 4 comments

Comments

@vsnig
Copy link

vsnig commented Apr 4, 2018

I believe such situation is unexpected and we should warn (or better error) when encountering it.
Right now it saves last extracted defaults and discards all the others.

I didn't look how to better do this but let it be here for now so we can later discuss and implement this.

@tricoder42
Copy link
Contributor

@lingui/babel-extract-messages` throws a syntax error when same message with different defaults is found in the same file, but maybe it's missed when messages are in different files?

@tricoder42
Copy link
Contributor

Fixed in latest release v2.3.0.

@tkvw
Copy link

tkvw commented Aug 21, 2018

I think we should allow undefined; this would allow to enter the default message once and use the id only in other cases.
Given:

<Trans id="about">About</Trans>

and:

<Trans id="about"/>

throws :

Error: Encountered different defaults for message about
pages/about.js:8 About
pages/index.js:26 undefined

@tricoder42
Copy link
Contributor

@tkvw The problem might be when message contains variables.

<Trans id="about">About {section}</Trans>

// becomes
<Trans id="about" defaults="About {section}" values={{ section }} />

// but we would have just
<Trans id="about" defaults="About {section}" />

so, yes, this should be possible, but you just have to pass values manually:

<Trans id="about" values={{ section }} />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants