Closed fzaninotto closed 7 years ago
This is a breaking change, and the warning is intentional.
Can you describe your use case where you can't just choose not to translate anything when you don't need any text?
Here is the React component I use in the admin-on-rest library:
const EditButton = ({ basePath = '', label = 'aor.action.edit', record = {}, translate }) => <FlatButton
label={translate(label)}
icon={<ContentCreate />}
containerElement={<Link to={linkToRecord(basePath, record.id)} />}
/>;
The idea is to offer a button with a label that the user can choose to override - or to remove, when called as follows:
<EditButton label="" basePath="/posts" record={record} />
Admin-on-rest is a framework to build admin GUI, so it must be very configurable, and let developers override pretty much anything.
Also, you say that the warning is intentional. Can you explain me the rationale?
So, in your case, label ? translate(label) : ''
should work just fine.
The warning is intentional because if you're calling a "translate" function with a value that wasn't previously seeded, it's very likely to be a bug.
Yes, I know how to overcome the warning, but I'd have to repeat this one liner in all buttons (I have many).
Besides, the empty string is not undefined
or null
. If the developer passes this value, it's intentional - and as such, it should not throw an error in the console. At least IMHO.
An empty string could be a valid translation key too.
In your case, you could just replace/alter your translate
function such that it doesn't attempt to translate the empty string, thus solving it in one location in your codebase.
Can you tell me what's the possible translation for the empty string as translation key, apart from an empty string? This doesn't make sense to me.
But you're right, whatever Polyglot doesn't do the way I want, I can do it myself. I just considered that the problem was with Polyglot and not the way I use it. I was probably wrong.
Some of the strings I translate can sometimes be disabled. Think for instance an Edit button, where the translation key is "edit", but that the developer can override to "" to hide the label.
When that happens, Polyglot warns in the console:
I think this edge case should be handled by the library.