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

Provide any way to translate exceptions titles #8931

Open
mrfatguy opened this issue Jun 29, 2015 · 31 comments
Open

Provide any way to translate exceptions titles #8931

mrfatguy opened this issue Jun 29, 2015 · 31 comments
Labels
status:ready for adoption Feel free to implement this issue.

Comments

@mrfatguy
Copy link

Currently using error actions is a non-sense in multi-language applications, because Yii2 returns exception titles untranslated, always in English and totally ignoring current user language. This is wrong.

While I agree on most samdark's statements, I believe that in context of translating exception titles, he made a two totally wrong assumptions.

First claim:

HTTP status codes are sent in headers and aren't intended for end users

is an obvious misunderstanding. How can you claim, that status codes are not intended for end users in context of 404, 403 or InvalidRouteException. What should be done, according to framework authors, if end user mistypes URL address (resulting in 404 or InvalidRouteException) or attempts to enter area of application, he/she is not authorised to? You're using exceptions in all these cases, but you claim, that exceptions are not meant for end user. What my application should do in these cases, according to you, to handle "situation" gracefully?

Second claim:

There's no difference if you as a user will get "Bad Request" or "Неверный запрос" if you're not familiar with HTTP etc.

is even a bigger false. My customer requires me to provide him with an application 100% translated, including exceptions and error titles, he is paying me for that, and he is for sure not going to accept explanation, that he'll see exception titles in English, because framework authors claims that translating them is wrong.

This is another example for Yii2 development shifting from providing best core engine into telling developers, that are using Yii2, how their applications should work. I can't recall any other framework in any other programming language, which authors are trying to tell end developers which part of their end application should be translated and which should remain in English. This is madness.

Related readings:

@samdark
Copy link
Member

samdark commented Jun 29, 2015

This is very right. Translated errors make no more sense for end user than untranslated ones except the user is developer. And in case of developer, getting emails with error reports with messages in a language he has no idea about is very inconvenient.

@samdark samdark closed this as completed Jun 29, 2015
@samdark
Copy link
Member

samdark commented Jun 29, 2015

Not found and access denied pages, if you want better UX, should be customized anyway i.e. handled with custom error handler to display funny images or provide search or suggest something. Just a message is not enough.

@samdark
Copy link
Member

samdark commented Jun 29, 2015

If the customer wants it bad, you can always replace exception classes with your own in bootstrap but, again, it's better to explain why it's a wrong thing to do.

@mrfatguy
Copy link
Author

I completely don't understand your point of view. How "Page not found" should be better to someone, who doesn't speak English at all, then the very same piece of text translated to language, that persons speaks? My customers are not moron and can understand what "Page not found" says, if it is translated to their language. They can't, if it is in English, because they don't speak English at all. I don't know, how easier could I explain this? Being or not being developer has nothing to do with this! These are so simple texts, that anyone can understand them, if only they're translated to language that particular user speaks.

Where is any logic in your thinking? How can translated exception titles be not understandable by end users, if exception message are understandable? Where is logic behind allowing translation of messages and blocking translation of titles in the same time? What is the reasoning for making exception constructor accepting any message (i.e. including translated ones) and not accepting exception title? What is the logic behind allowing user to modify message body (text) by changing constructor parameter and forcing him/her to use own classes to modify title. Finally -- where is the logic in displaying error view with translated error message and not translated error title?

You haven't even tried to counterargument my key argument -- Yii2 is probably the only framework out there, that forces developer by telling h im/her what should or what shouldn't be translated. While translation should be as open and as transparent as possible -- everything should be able to be translated, if one wants, without playing with replacing core classes. This is wrong.

Can you present any framework or programming language, that displays any kind of message box, alert or information to end user and has parametrized (easily changeable) message body, but fixed and unchangable message title? Anyone? At least one? This is madness, samdark!

What is most important here, is that you -- creator / creators of Yii -- are again forcing some solutions, understandable only by you, instead of give a choice to end developer. If you would place translation of exception titles into standard translation files, but left it in English, then both sides would be satisfied. Developers, who want to have them translated could provide their own translation files and override default translation. People, like you, who thinks, that this should remain in English, would simply use default translation files. Period.

But in current solution, since exception classes does not use Yii::t, only people like you are satisfied. And developers, like me, who disagree, must "fight" with stupid workarounds and similar idiotic solutions only because you told us, that this is better. Do you feel absurd in this way of thinking? You're making Yii2 only more and more hermetic and following your point of view, while actually it should be made as open as possible. What you're doing with Yii since Yii2 was born is bad. Not everyone thinks like you think. I know, that this is hard to understand and accept. But this scheme repeats in many bugs and issues around Yii2. You're making it so hermetic. There was so much openness around Yii1 which is now long gone.

To summarize, if you really think, that exception classes should have titles in English, then use Yii:t, but leave them in default translation files (in all languages) in English with proper comment. Or parametrize constructor of exception, so it accept both message body and message title. Or do anything, that would end developer, not you to decide what is and what isn't translated!

@nineinchnick
Copy link
Contributor

Error handling including translations should be left to the developer. The framework doesn't force anything here. Your error handler actions should use customized and translated views instead of just displaying raw error message.

This is also a security concern as you can reveal sensitive information in error messages if you do not control which ones are displayed.

@samdark maybe docs should include some example how to override few selected exception classes, like NotFoundException? I usually exclude 4XX errors from my email error handler anyway.

@samdark
Copy link
Member

samdark commented Jun 29, 2015

@trejder you're constantly repeating argument about "not found" exception but, in fact, it is translated and there are translation files for it. I forgot about it too :)

@samdark
Copy link
Member

samdark commented Jun 29, 2015

In general, if the message is meant to be displayed to end user, such as "not found", it's translated. If not, such as the same response from API or rather cryptic messages like "internal exception", they are not.

@samdark
Copy link
Member

samdark commented Jun 29, 2015

@trejder if you think particular message should be translated because it makes sense to non-tech user, let me know and it will be translated but I'm totally against translating very tech messages.

@mrfatguy
Copy link
Author

I am talking about exception / error message's title!

Right know (current Yii2 implementation) I'm getting for user using Polish language something like this:

Not Found (#404)
Nie odnaleziono strony.

clipboard01

No, known to me, solution allows me to translate this error view title (contents of <h1></h1> section or value of $name, that comes from Exception), because exceptions itself always brings name untranslated, always in English, no matter, what language user uses.

Correct me, if I'm wrong.

@samdark
Copy link
Member

samdark commented Jun 29, 2015

Hmm... https://github.com/yiisoft/yii2/blob/master/framework/messages/pl/yii.php#L38 should be translated. Are you throwing this exception yourself?

@samdark samdark reopened this Jun 29, 2015
@samdark samdark self-assigned this Jun 29, 2015
@bizley
Copy link
Member

bizley commented Jun 29, 2015

@mrfatguy
Copy link
Author

@samdark No, it is not translated. Either there is a bug in Polish translation core file (didn't check other languages) or you're talking about different string. Notice, that you're pointing to the line, that translates Page not found. string, while exception on my screenshot has $name set to Not Found or Not Found (%d) or something similar.

It the result:

  • it printsNot Found (#404):
    • all capitalized,
    • without Page part,
    • with error number inside brackets,
    • without dot at the end,
  • not Page not found.:
    • with Page part,
    • without error number,
    • with dot at the end
    • not all capitalized.

There's 95% chances, that these are two completely different strings and maybe that's why translation does not "catch" this one and does not translate exception name? Assuming that exception names are translated at all, because @bizley-code founding suggest that not.

Exception presented at this particular screenshot is thrown by Yii2 itself, when user enters a non-existing route, for example http://127.0.0.1/web/no-such-controller/no-such-action. But, I'm getting exactly the same effects (exactly the same view rendered, feed with exactly the same strings), when I throw this extension myself, for example in Gii-generated findModel() method.

protected function findModel($id)
{
    if (($model = Lab::findOne($id)) !== null) {
        return $model;
    } else {
        throw new NotFoundHttpException('The requested page does not exist.');
    }
}

Either way, it seems, that at current stage, there is no way to translate Exception::name attribute. It seems to be in English always, no matter, what language user has set as default.

@mrfatguy
Copy link
Author

This case is not narrowed to 404 or 403 exceptions:

clipboard01

Yii2 should allow translation of all exceptions' names / titles IMHO, to produce reasonable results. I can't imagine any page in Yii application only partially translated, no matter what you think about whether exceptions' names / titles should or shouldn't be translated.

@samdark
Copy link
Member

samdark commented Jun 30, 2015

How to deal with user reports sent to support@site.com that are in, for example, Greek while you understand English only?

@samdark
Copy link
Member

samdark commented Jun 30, 2015

But yes, I understand what you mean. Framework should be more flexible in this area if it's actually such a strong requirement in some cases.

@mrfatguy
Copy link
Author

How writing Greek e-mail to English support relates to having error view (or any other part of application) only partially translated, samdark? :>

If your Greek user does not understand even a bit of English, he/she will not understand Internal Server Error (#500) and will have to see it as Εσωτερικό σφάλμα διακομιστή (# 500)! :> Which is, currently, not possible in Yii 2.0.4, right?

@nineinchnick
Copy link
Contributor

@samdark exceptions visible to the end user in general should be only 4XX errors, that is non critical. Usually they're not sent using a mail logger, that would spam the devs/admins. They do however need to be translated.

On the other hand, 5XX errors should not be displayed with details and should be logged and sent to devs. Those shouldn't be translated.

@mrfatguy
Copy link
Author

@nineinchnick I disagree with you, that 5xx errors shouldn't be translated (I do, however, agree, that they should not bring too much detail to end user). In my opinion (shared by many of my colleagues), displaying untranslated error, exception or message is wrong in all conditions. Showing end-user an English 5xx error instead of the one in his/her selected language does not lower security even a bit (providing, that there are no more details except for exception name and message), but is less comfortable and reduces overall application perception.

Beside, discussion, which HTTP errors should and which shouldn't be translated is wrong here. It is up to the end developer, not framework creators. All exception names and messages should be exported to core translation files and all core exceptions should use Yii:t. Error texts and exception names in translated files can remain in English, if that bothers you and others so much (I disagree, that translation of anything can lower security, if other details are not provided). But, translation of all exceptions should be possible, if end developer decides so, because this is his/her decision. Currently, it isn't possible for exception names.

@nineinchnick
Copy link
Contributor

@trejder samdark already agreed that it should be more flexible.

@mrfatguy
Copy link
Author

@nineinchnick Just to clarify -- I'm aware of this. My previous comment was addressed to you to counterargument your statement:

On the other hand, 5XX errors (...) Those shouldn't be translated.

As I disagree with you and think, that all kind of errors should be enabled for translation.

@sauron918
Copy link

I agree with @nineinchnick

Yii2 does not call for translation title: https://github.com/yiisoft/yii2/blob/master/framework/web/ErrorAction.php#L87

I have an error page title Not Found (#404) and error page text Страница не найдена on the different languages. I think it is not right.

translate

How easy to translate error page title?

PS. Similar question on Stack Overflow

@mrfatguy
Copy link
Author

Do we have any progress or update on this case after half a year has passed? Anything?

@SilverFire
Copy link
Member

As far as I see - no. Unfortunately, the discussion stopped without good design decision.

I agree, that it is good idea to translate the exception message to customer's language.
@samdark, in email notifications you always have much more information about the exception, such as exception class name, stack trace, etc. You always can figure out, what's happened indeed.

I'm suggesting to modify method getName in all exceptions as it goes from the following example:

diff --git a/base/UnknownMethodException.php b/base/UnknownMethodException.php
index 6e33490..f4fde04 100644
--- a/base/UnknownMethodException.php
+++ b/base/UnknownMethodException.php
@@ -16,10 +16,11 @@ namespace yii\base;
 class UnknownMethodException extends \BadMethodCallException
 {
     /**
+     * @param bool $translate Whether to translate the exception message to the application language.
      * @return string the user-friendly name of this exception
      */
-    public function getName()
+    public function getName($translate = true)
     {
-        return 'Unknown Method';
+        return $translate ? \Yii::t('app', 'Unknown Method') : 'Unknown Method';
     }
 }

Then, we can use $e->getName(false) in email notifications or elsewhere.

@yiisoft/core-developers thoughts?

@samdark
Copy link
Member

samdark commented Mar 11, 2016

I don't like the idea of translating exception titles at all. If you want to be nice to end user you'll create custom error handler anyway. As a developer it's confusing getting messages in the language you don't understand (when users are copy-pasting exceptions and sending these to you).

@mrfatguy
Copy link
Author

I don't like the idea of translating exception titles at all. If you want to be nice to end user you'll create custom error handler anyway.

And any reason for that? Any reason, why you don't like the idea of translating the titles, but you do like the idea of translating everything else? Because -- as you can see on screen-shots -- error title is the only thing that remains untraslated. Everything else is easily translatable.

And, again. Can you give any reason or explanation, why Yii is forcing me to write custom error handler to translate error title only? Because, I don't need to use it, when translating title body (text), links etc.

I completely don't understand your point of view. Don't get it personal, but that sounds like a complete non-sense to me.

As a developer it's confusing getting messages in the language you don't understand (when users are copy-pasting exceptions and sending these to you).

Can you further elaborate your point, because -- again -- I don't understand you. Of course, it is confusing to receive messages in the language you don't understand. And that's the whole point of this ticket. I don't want my users to see error titles in the language, they don't understand! Currently, they do. Currently they see error title in English, while error message, links etc. in Polish.

@samdark
Copy link
Member

samdark commented Mar 11, 2016

Well, I was against translating exception messages as well. But since it's already there I'm OK to translating titles...

@samdark
Copy link
Member

samdark commented Mar 11, 2016

To clear my point...

I don't want my users to see error titles in the language, they don't understand!

Non-techy users won't understand database related error or insufficient permissions or anything else other than probably 404 no matter what language it would be. And 404s ideally should be customized to be helpful. Provide a search form or suggest something or at least say sorry...

What users will do is copy-pasting everything from the error page or screenshotting it and sending it to support.

@mrfatguy
Copy link
Author

My seventy years old mother won't understand neither 404 nor Page Not Found. But, she will understand Strona nie znaleziona (in her native language). Any other arguments?

Plus: Having Polish message body with English title (or any other mixture of languages) in one view is a complete non-sense in terms of user interface / user experience.

We're rounding and rounding around, what member will or will not understand, what is technical or not, what is better, what is worse. But, that's not a point. Framework (any) should not limit me from what I'm able to translate in my own application. Limiting me here in any matter or kind if wrong.

Saying, that I can translate message body by hand, but I need to overwrite base framework objects & methods and provide my custom ones to translate message title, is a complete stupidity to me. Sorry!

@samdark
Copy link
Member

samdark commented Mar 11, 2016

My seventy years old mother won't understand neither 404 nor Page Not Found. But, she will understand Strona nie znaleziona (in her native language). Any other arguments?

404 is special and, ideally, as I said before, should be more user friendly. Would she understand "Internal server error" or "database connection problem" or "insufficient credentials" if it would be in Polish?

Plus: Having Polish message body with English title (or any other mixture of languages) in one view is a complete non-sense in terms of user interface / user experience.

Agree. That's why #8931 (comment)

Framework (any) should not limit me from what I'm able to translate in my own application. Limiting me here in any matter or kind if wrong.

What we're going to do isn't about you choosing to translate exceptions in your app or not. It's translating exception when certain language set. In all apps. By default.

Saying, that I can translate message body by hand, but I need to overwrite base framework objects & methods and provide my custom ones to translate message title, is a complete stupidity to me. Sorry!

You're right. Initially I was against allowing body translations as well but since it's already there, adding title is OK: #8931 (comment)

@samdark samdark added status:ready for adoption Feel free to implement this issue. and removed status:under discussion labels Mar 11, 2016
@mrfatguy
Copy link
Author

404 is special and, ideally, as I said before, should be more user friendly. Would she understand "Internal server error" or "database connection problem" or "insufficient credentials" if it would be in Polish?

Whatever example you're going to bring, I'll say, that she will understand it, if it is in Polish. She won't understand it, if it remains in English even though entire website is in Polish.

She is seventy years old. She hardly reads anything except titles! :>

Agree. That's why #8931 (comment)

I missed that comment initially. I found it "glued" to your previous post only after sending my reply. Sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready for adoption Feel free to implement this issue.
Projects
None yet
Development

No branches or pull requests

6 participants