jsxlate
jsxlate copied to clipboard
Favor call message over element message on matches
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.
Coverage increased (+0.03%) to 91.915% when pulling b645c2804309c4ab23751406a3806c29ab4ac810 on bauerca:master into e7a159e8e409d7bd1ee69d949914d005080f386b on drd:master.
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