How do I modify YII core message when no translation file exists?
Yii does not provide a translation message file for the en_us language. Instead, we are expected to rely on the core messages to be correct.
If I was successful in finding where the core messages are held, I still wouldn't want to mess with the core file because, A. it is ill-advised and B. future version revisions would overwrite my changes.
Is my only alternative to copy any other language message file and hand edit every single message so that the translated message is the same as the english message (with my correction(s) in place? It seems like a lot of work for the sake of one word that needs correcting.
The reason I bring this up is this...
If you navigate to a non-existent page, their error message is: 'The requested view "{name}" is not found.' I think it should say: 'The requested view "{name}" was not found.'
I argue that they are mixing tenses in this statement ('requested' = past tense and 'is开发者_开发知识库' = present tense).
Rightly or wrongly, I am 'uncomfortable' with their grammar.
Yii is open source. Why not submit your patch?
The messages can be found in yii-read-only/framework/messages/, you may want to have a look at yii-read-only/framework/messages/config.php too.
Also, you could use the message command for yiic.
As for the actual problem, you can find any message with fgrep:
fgrep -rn "The requested view" *
And the result:
framework/web/actions/CViewAction.php:110: throw new CHttpException(404,Yii::t('yii','The requested view "{name}" is not found.',
So go out there, check out the SVN trunk, modify, then "svn diff", and submit your patch on google code.
No need to patch the core files to get this to work. Take a look at http://www.yiiframework.com/wiki/18/how-to-customize-yii-core-messages/
If you try to set your language to en_us in main.php, hoping to use the local yii.php in protected/messages/en_us it won't work. It won't translate because the language setting of 'en_us' in main.php is the same as the core language; so you need to force a translation.
The solution is to create a new language, that only overrides the messages you want to change/fix. So, following the example shown at the link above, use en instead of de as the language in main.php. Create an en folder rather than a de folder under protected/messages.
Then create your customized yii.php file in the local en folder, which in your case would only contain
return array (
'The requested view "{name}" is not found.' => 'The requested view "{name}" was not found.',
);
THIS way, no need to adjust core files; and, your changes will remain across framework version upgrades.
As an FYI, IF the Yii::t('yii',...) call you find using GREP is actually to Yii::t(' zii ',...) then you need a zii.php file rather than a yii.php file in the protected/messages/en folder. It would use exactly the same format as the yii.php code shown above.
This useful for messages like the one returned when there are no search results.
精彩评论