You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey @tembra ,
I just wanted to drop a line and ask, if it is possible to add an "internationalization" (i18n) feature for your plugin.
I really like it and use it in my current project. However, I need to output exceptions in different languages (depending on the user's Accept-Language).
Can you give me a feedback on this topic?
Cheers from Germany
@johannesschobel sorry for late answer.
I'm currently finishing my application for production and for now the multi-language support isn't a need. But once I got some free time I'll make this improvement.
I like your idea of use Accept-Language header, but this can't be the only way.
What I'm planning for this package is to have a new index named languages inside value of $errors associative array, that you can set on your Application Error Code class. This member will be an associative array with language code (e.g. en or pt_BR) as index and another array as value that will be an associative array too with title and detail members as index and the translated message as value.
Something like this:
<?phpuseMytdt\JsonApi\Errors\MyJsonApiErrors;
class AppErrorCodes extends MyJsonApiErrors
{
constRESOURCE_NOT_FOUND = 1;
protectedstatic$errors = [
self::RESOURCE_NOT_FOUND => [
'title' => 'Resource not found',
'detail' => 'The requested resource was not found'
'languages' => [
'pt_BR' => [
'title' => 'Recurso não encontrado',
'detail' => 'O recurso solicitado não foi encontrado.'
]
],
];
}
Then when return error object all we need to do is verify which language to use and get properly title and detail members, from root or from languages array.
If you feel comfort to implement something like this or have another vision/way to do so, you're welcome to contribute to this package and send a PR.
Activity
johannesschobel commentedon Jan 31, 2017
Hey @tembra ,
I just wanted to ask, if there are any updates on this issue!?
tembra commentedon Feb 6, 2017
@johannesschobel sorry for late answer.
I'm currently finishing my application for production and for now the multi-language support isn't a need. But once I got some free time I'll make this improvement.
I like your idea of use
Accept-Languageheader, but this can't be the only way.What I'm planning for this package is to have a new index named
languagesinside value of$errorsassociative array, that you can set on your Application Error Code class. This member will be an associative array with language code (e.g.enorpt_BR) as index and another array as value that will be an associative array too withtitleanddetailmembers as index and the translated message as value.Something like this:
Then when return error object all we need to do is verify which language to use and get properly
titleanddetailmembers, from root or from languages array.If you feel comfort to implement something like this or have another vision/way to do so, you're welcome to contribute to this package and send a PR.