Factor out dependency on i18n
Opened this issue · 0 comments
alexweissman commented
Would be cool if we could decouple Fortress' dependence on MessageTranslator
for translating validation error messages.
What should probably happen instead, is that Fortress should simply return the raw translation keys + placeholder data in its error messages. This would then be passed to the i18n component for translation.
Perhaps at the same time, we could tackle the TODO that's all over UF's controller methods:
// Validate, and throw exception on validation errors.
$validator = new ServerSideValidator($schema, $this->ci->translator);
if (!$validator->validate($data)) {
// TODO: encapsulate the communication of error messages from ServerSideValidator to the BadRequestException
$e = new BadRequestException();
foreach ($validator->errors() as $idx => $field) {
foreach($field as $eidx => $error) {
$e->addUserMessage($error);
}
}
throw $e;
}
In this case, the raw translation keys+data should probably percolate all the way through the BadRequestException
as well, and only get translated right at the point when they are about to be rendered for the user (so, Twig template or alert stream).