Image localization

Hi, I´m trying to develop a bilingual site, I already managed static pages localization, but I´m having hard times when it comes to image localization.

According to the Yii guide,


should do the trick, but I´m experiencing troubles with paths…

In the site I insert and images like

<img src="<?php echo Yii::app()->request->baseUrl; ?>/img/image.png"></img>

and it does work.

But when trying to localize that same URL:

<img src="<?php echo Yii::app()->findLocalizedFile(Yii::app()->request->baseUrl . '/img/image.png'); ?>"></img>

is does not.

The reason I see is that getLocalizedFile uses is_file, and it dislikes URLs like

Yii::app()->request->baseUrl . 'img/image.png'

, though it seems to like the ones that include some server data like:

Yii::getPathOfAlias('webroot') . '/img/image.png'

So to resume, is_file(through getLocalizedFile) likes a webroot like URL, but does not a baseUrl one. On the contrary, <img> html tag likes baseUrl, but does not webroot.

Any thoughts?

Did you check the generated URL?

baseUrl by default return a relative path… try with the absolute path… for this use getBaseUrl(false) - http://www.yiiframew…tBaseUrl-detail

Ok, will try it, I overlooked that. It was just found odd that if_file cannot work with relative paths. Thanks.