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

[REQ] POEdit files generator #6057

Open
ybelenko opened this issue Apr 26, 2020 · 0 comments
Open

[REQ] POEdit files generator #6057

ybelenko opened this issue Apr 26, 2020 · 0 comments

Comments

@ybelenko
Copy link
Contributor

ybelenko commented Apr 26, 2020

Is your feature request related to a problem? Please describe.

Imagine multilingual API. There are hardcoded messages which should be translated. The first thing comes to mind is error messages.

components:
  schemas:
    ClientError:
      error_code:
        type: integer
        example: 400
      error_message:
        type: string
        example: 'Bad request.'

Describe the solution you'd like

en_US.po file:

# it's not enough for all errors, but for 400 bad request as a start
msgid "ClientError.error_message"
msgstr "Bad request."

# obviously error_message field is dynamic then you might need more messages
# uncomment more strings and specify IDs for them
# msgid "ClientError.error_message.2"
# msgstr ""

# msgid "ClientError.error_message.3"
# msgstr ""

ru_RU.po will be identical but user fills in russian translations.

Describe alternatives you've considered

And even more crazy idea. It's really boring to document hundreds of errors in every project. What about multilingual API Error Codes Book file? I think that 99% of APIs use static codes for errors and most of time they are hardcoded. We can generate .po file with error codes mapped to HTTP Status Codes from official standard. We can add template for custom errors like msgid "error_555" etc. If developer uses error code 555 he uncomments this line and adds appropriate message translation.

After that PHP user can use translations with gettext extension like:

$language = "ru_RU";
putenv("LANG=".$language);
setlocale(LC_ALL, $language);

$domain = "error_messages";
bindtextdomain($domain, "locale");
textdomain($domain);

echo gettext("error_400");
/* prints Неверный запрос. */

cc special invite to @jimschubert

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

No branches or pull requests

1 participant