How to translate exception titles in Yii 2?

I’m unable to translate exception’s titles. When language is set to non-English, I have everything translated except “Not Found” title (in case of NotFoundHttpException). What approach should I take to get this translated as well and why this isn’t translated by default (i.e. “exported” to default language / translation files)?

I have asked a very similar question on Stack Overflow and got a pretty nice looking answer. But, I still can’t believe, that we have to “play” with this kind of workaround, because this – so extremely obvious problem – isn’t handled by default. Can someone out of dev team shed some light, why this isn’t handled by default and must be solved using such weird approaches?

BTW: I wrote “an extremely obvious problem”, because I can’t imagine, how one can omit exception titles in base framework translation? I mean, what good do we have if entire application is translated, but exception titles are not?

I think exceptions shouldn’t be left to display but caught and properly handled. I guess the dev team has got the same concept https://github.com/yiisoft/yii2/issues/3593

Everything is here anyway http://www.yiiframework.com/doc-2.0/guide-runtime-handling-errors.html

What do you mean by "caught and properly handled" in case of exceptions like 404 or 403? How would like to handle this properly, if the only handling I can think of, is to display proper message to end user?

Handling errors (section in docs) has nothing to do with this, because, when you’re using error actions, you get name of error untranslated (totally ignoring your current language). And that is the whole point here.

Also, take a look at this: https://github.com/yiisoft/yii2/issues/8931#issue-91730833

Maybe you are right - I have not tested this so far but what about this http://www.yiiframework.com/doc-2.0/guide-runtime-handling-errors.html#customizing-error-response-format ? It looks like you can prepare custom message.

Oh, I get the feeling that using custom response formatting is just too heavy for this case.

If framework authors won’t change their mind and will continue to claim, that exception titles should remain in English, no matter what language end user is using, then I’m pretty much more for making this change as a local override. In either own exception class that overrides default one or even as nasty solution as doing text replacement directly in view. We’re – after all – talking about actually just a few exceptions, that should went to the end user. All others should indeed remain in English (to have proper psychological effect on dummies) or should be handled in any other way, as you suggested.

I don’t think, that using custom response format is a good idea in this case. And I certainly don’t like the idea of running any custom code declared directly in configuration, as docs section mentioned by you is suggesting.

Well, this is just an event so you handle it in different way.

Anyway, when using error action http://www.yiiframework.com/doc-2.0/guide-runtime-handling-errors.html#using-error-actions you can specify the view for it and prepare the message you want to display for every kind of exception you like (see http://www.yiiframework.com/doc-2.0/yii-web-erroraction.html )

I understand that this is an extra work and could be avoided with the exception statuses translated.

A this point, the fact, that exception titles are not translated doesn’t bother me that much, like the fact, that core developers think they shouldn’t be translated at all and all these false logic behind, I pointed out in my new issue.

Yii2 development shifts dangerously into telling developers, how their app should work and I’m pretty sure, that my issue will be closed and I’ll have to handle this problem myself, while all arguments tells (at least according to me), that this should be handled at framework level.

But, this makes this discussion a bit off-topic, don’t you think? :> Thanks!