jsxlate icon indicating copy to clipboard operation
jsxlate copied to clipboard

Favor call message over element message on matches

Open bauerca opened this issue 9 years ago • 3 comments

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.

bauerca avatar May 17 '16 00:05 bauerca

Coverage Status

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

coveralls avatar May 17 '16 00:05 coveralls

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

drd avatar May 20 '16 16:05 drd

Coverage Status

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

coveralls avatar May 20 '16 21:05 coveralls