English 中文(简体)
How do I modify YII core message when no translation file exists?
原标题:
  • 时间:2010-02-06 02:44:07
  •  标签:
  • php
  • yii

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.





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签