在magento的Block、phtml视图和控制器中都能够使用方法__()来翻译,该方法会根据提供的参数到app/locale/zh_CN(或其它当前语言目录)下搜索.csv文件中对应的翻译内容
__()函数是可以带参数的,从而实现动态翻译,下面是几种用法
1、不带参数
$this->__("gift for you");
这时候只要在csv文件中添加这么一句就能达到翻译的目的
"gift for you","这是给你的礼物"
2、带一个参数
$this->__('Can\'t save description %s', Mage::helper('core')->htmlEscape($description))
翻译格式:
"Can't save description %s","无法保存说明%s"
$this->__('My Wishlist (%d item)', $count);
"My Wishlist (%d item)","我的收藏 (%d件商品)"
3、带多个参数
$this->__('%1$s has been added to your wishlist. Click <a href="%2$s">here</a> to continue shopping.', $product->getName(), Mage::helper('core')->escapeUrl($referer));
"%1$s has been added to your wishlist. Click <a href=""%2$s"">here</a> to continue shopping.","%1$s 成功添加到收藏,点<a href=""%2$s"">这里</a>继续购物"