开发者

Zend internationalized view helper

in my current project, I need to to use a helper and I would like to translate the string inside this view helper in my .po files. So, I think i need to use the translate() helper but I don't figure out how to use it in a helper.

Here is the helper I found on the web :

<?php

/**
*
* @category View_Helper
* @package Custom_View_Helper
* @author Chris Jones <leeked@gmail.com>
* @license New BSD License
*/
class Zend_View_Helper_HumaneDate extends Zend_View_Helper_Abstract {
    /**
    * Various time formats
    */
    private static $_time_formats = array(
        array(60, 'un instant'),
        array(90, '1 minute'), // 60*1.5
        array(3600, 'minutes', 60), // 60*60, 60
        array(5400, '1 heure'), // 60*60*1.5
        array(86400, 'heures', 3600), // 60*60*24, 60*60
        array(129600, '1 jour'), // 60*60*24*1.5
        array(604800, 'jours', 86400), // 60*60*24*7, 60*60*24
        array(907200, '1 semaine'), // 60*60*24*7*1.5
        array(2628000, 'semaines', 604800), // 60*60*24*(365/12), 60*60*24*7
        array(3942000, '1 mois'), // 60*60*24*(365/12)*1.5
        array(31536000, 'mois', 2628000), // 60*60*24*365, 60*60*24*(365/12)
        array(47304000, '1 année'), // 60*60*24*365*1.5
        array(3153600000, 'années', 31536000), // 60*60*24*365*100, 60*60*24*365
        );
    /**
    * Convert date into a pretty 'human' form
    *        Now with microformats!
    *
    * @param string $ |Zend_Date $date_from Date to convert
    * @return string
    */
    public function humaneDate($date_from)
    {
        $date_to = new Zend_Date(null, Zend_Date::ISO_8601);
        if (!($date_from instanceo开发者_开发问答f Zend_Date)) {
            $date_from = new Zend_Date($date_from, Zend_Date::ISO_8601);
        }
        $dateTo = $date_to->getTimestamp(); // UnixTimestamp
        $dateFrom = $date_from->getTimestamp(); // UnixTimestamp
        $difference = $dateTo - $dateFrom;
        $message = '';
        if ($dateFrom <= 0) {
            $message = 'il y a longtemps';
        } else {
            foreach (self::$_time_formats as $format) {
                if ($difference < $format[0]) {
                    if (count($format) == 2) {
                        $message = 'il y a ' . $format[1];
                        break;
                    } else {
                        $message = 'il y a ' . ceil($difference / $format[2]) . ' ' . $format[1];
                        break;
                    }
                }
            }
        }
        return sprintf('<abbr title="%sZ">%s</abbr>',
            $date_from->get('YYYY-MM-ddTHH:mm:ss'),
            $message
            );
    }
}

Any idea ?


As your helper extends Zend_View_Helper you can access anything like in view using the $view memeber variable of the helper. Use this syntax:

$this->view->translate('something');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜