Weird and inconsistent params substitutions in Yii:t

Hi, I posted about this on the General Discussion, but I guess this is a bug, or it could cause bugs if one doesn't pay attention. From the helloworld demo:

<?php





class SiteController extends CController


{


	public function actionIndex()


	{


	   $world = 'World Series';


		echo Yii::t('demo', 'Hello world', array('world'=>$world));


	}


}

Output:

[tt]Hello World Series[/tt]

This could be solved using this modified [tt]YiiBase::t[/tt] method:

<?php


public static function t($category,$message,$params=array())


	{


		if(self::$_app!==null)


		{


			$source=$category==='yii'?self::$_app->getCoreMessages():self::$_app->getMessages();


			if($source!==null)


				$message=$source->translate($category,$message);


		}


		if (is_array($params) && $params !== array()) {


		   foreach ($params as $key => $val) {


		      $message = str_replace('{' . $key . '}', $val, $message);


		   }


		}


     return $message;


	}

with the benefit that you dont need to surround the key with [tt]{ }[/tt] in the params array, making it nicer. I don't think the performance impact would be so high.

This is by design. Yes, it requires you to type in the whole placeholder (including the curly brackets if you use them). This makes it possible to use arbitrary placeholders instead of just the ones enclosed in brackets.

Quote

This is by design. Yes, it requires you to type in the whole placeholder (including the curly brackets if you use them). This makes it possible to use arbitrary placeholders instead of just the ones enclosed in brackets.

Hmm, oki. Maybe putting this clarification on the guide should be useful for pradoers :)

Thanks Qiang.

Agree, complete replacement is more consistent with PDO bind parameters as well.