Skip to content

Favor call message over element message on matches#16

Open
bauerca wants to merge 2 commits intodrd:masterfrom
bauerca:master
Open

Favor call message over element message on matches#16
bauerca wants to merge 2 commits intodrd:masterfrom
bauerca:master

Conversation

@bauerca
Copy link

@bauerca bauerca commented May 17, 2016

It is possible for i18n("string") and <I18N>string</I18N> to exist in the same project. If the element version is parsed by jsxlate after the function call version, the bundle will contain:

{
  "string": function() { return <span>string</span>; }
}

when it should return:

{
  "string": function() { return "string"; }
}

because the result of the function call should be a string and not a React element. The jsxlate <I18N> component is smart enough to wrap the string in a <span> if it does not receive a React element from the translation renderer.

This PR fixes the issue by preferring the function-call renderer (which returns a string) over the jsx element renderer when their messages match.

@coveralls
Copy link

coveralls commented May 17, 2016

Coverage Status

Coverage increased (+0.03%) to 91.915% when pulling b645c28 on bauerca:master into e7a159e on drd:master.

'<Pluralize:items><Match when="=0">You have no items in your cart</Match><Match when="one">You have one item in your cart</Match><Match when="other">You have {this.state.count} items in your cart</Match></Pluralize:items>':
'<Pluralize:items><Match when="=0">No tiene nada in su carrito</Match><Match when="one">Tiene ún articulo en su carrito</Match><Match when="other">Tiene {this.state.count} articulos en su carrito</Match></Pluralize:items>'
'<Pluralize:items><Match when="=0">No tiene nada in su carrito</Match><Match when="one">Tiene ún articulo en su carrito</Match><Match when="other">Tiene {this.state.count} articulos en su carrito</Match></Pluralize:items>',
'Hey': 'Hey'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls to trailing comma

@drd
Copy link
Owner

drd commented May 20, 2016

This is one solution to this. Another solution would be to change how bundles are defined at translation time, where you could keep separate objects for element/call messages and then merge with the call messages winning. That's a bit of a deeper change so I'm fine with this, but if you're feeling plucky I'd be happy to assist with the other way! I'll merge this after you fix the commas. <3

@coveralls
Copy link

coveralls commented May 20, 2016

Coverage Status

Coverage increased (+0.03%) to 91.915% when pulling 8c83160 on bauerca:master into e7a159e on drd:master.

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

Successfully merging this pull request may close these issues.

3 participants