Open tomaszkane opened 1 year ago
What would you do with that null
?
Nothing. It just "This key does not have translation, so return nothing". I create translations for RBAC items:
return [
'label.foo-read' => 'Foo label - it should be requred',
'description.foo-read' => 'Foo description - its optional.',
'label.boo-delete' => 'Boo',
// 'description.boo-delete' => 'Boo description is not necessary.',
];
Now I must set EventDispatcherInterface and catch exceptions or write dummy IF's like:
$translated = $translator->translate('description.boo-delete', category: 'foo');
if ('description.boo-delete' !== $translated) {
$someOutput .= $translated;
}
I think we may add some fallback function to let users decide what to do with missing translations.
But null
is impossible because of return type.
Will it be ok for you?
Empty string is ok.
What steps will reproduce the problem?
Use Translator on not-existed key.
What is the expected result?
I want to decide when
translate()
should returnkey
ornull
.Throwing exception on missing translations is to complicated here.
I want to decide if given translate category return
null
on missing key or given TranlateInterface instance.Additional info