Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I18n for Errors #4

Open
johannesschobel opened this issue Oct 19, 2016 · 2 comments
Open

I18n for Errors #4

johannesschobel opened this issue Oct 19, 2016 · 2 comments

Comments

@johannesschobel
Copy link

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
Copy link
Author

Hey @tembra ,
I just wanted to ask, if there are any updates on this issue!?

@tembra
Copy link
Owner

tembra commented 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-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:

<?php

use Mytdt\JsonApi\Errors\MyJsonApiErrors;

class AppErrorCodes extends MyJsonApiErrors
{
    const RESOURCE_NOT_FOUND = 1;

    protected static $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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants