pi-engine / pi

Multi-tenant application development engine for cloud ready SaaS platform.
http://www.piengine.org
202 stars 115 forks source link

Local calendar #24

Closed voltan closed 11 years ago

voltan commented 11 years ago

Hi

support local calendar is to important for us. and whit php 5.3 and intl its very easy . just need one line code :

$fmt = new IntlDateFormatter("fa_IR@calendar=persian", IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'Asia/Tehran', IntlDateFormatter::TRADITIONAL);
return $fmt->format($date);

But I don't know what is the best way for use it in PI. We need general date manager function for support all languages / calendars. At this moment we use date function for make date. we need change / update it.

date('Y-m-d H:i:s', $data['update'])

And use it all codes for example as i18n/View/Helper/DateFormat.php in templates and rewrite it for support local calendar

voltan commented 11 years ago

And if support in controller is very good for ajax functions and json outputs

taiwen commented 11 years ago

I am working on it. Can you give some use cases?

voltan commented 11 years ago

I'll send live pi example here in next two hour after finish server config

voltan commented 11 years ago

I add this line in template ( just for test )

$fmt = new IntlDateFormatter("fa_IR@calendar=persian", IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, 'Asia/Tehran', IntlDateFormatter::TRADITIONAL);

And use this function for make date

$fmt->format(intval($message['create']));

And template is here : https://github.com/taiwen/voltan/blob/master/usr/module/sms/template/front/list.phtml

I add some changes in date format and get image for result :

1- Persian calendar whit Persian text

$fmt = new IntlDateFormatter("fa_IR@calendar=persian", IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, 'Asia/Tehran', IntlDateFormatter::TRADITIONAL);

pi3

2- Persian calendar whit English text

$fmt = new IntlDateFormatter("en_US@calendar=persian", IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, 'Asia/Tehran', IntlDateFormatter::TRADITIONAL);

pi1

3- Gregorian calendar whit English text ( default )

$fmt = new IntlDateFormatter("en_US", IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, 'Asia/Tehran', IntlDateFormatter::TRADITIONAL);

pi2

4- Gregorian calendar whit Persian text

$fmt = new IntlDateFormatter("fa_IR", IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, 'Asia/Tehran', IntlDateFormatter::TRADITIONAL);

pi4

For use cases, it need for all date outputs , I think for each website / language we need some settings. Like :

And mvc plugin / view helper / i18n class, for use it in all controllers / template / other parts

taiwen commented 11 years ago

We also need use cases for NumberFormatter

voltan commented 11 years ago

I test this helper in i18n : http://framework.zend.com/manual/2.0/en/modules/zend.i18n.view.helpers.html#numberformat-helper

For Persian / Arabic language it has good support ( here for example : http://www.payamakyab.com/ ), just we need tools for set NumberFormatter and local

voltan commented 11 years ago

Thank you very much, It work for me fine , just two points : 1- It possible to update pi module codes and use _date() functions 2- I am not sure, But perhaps it bug, when I change timetype and datetype its not work, I'll test on other machine

taiwen commented 11 years ago

Can we use _date() in Pi modules? Kind of complicated:

A tricky solution is:

    if (_intl()) {
        // Use _date();
    } else {
        // Use date();
    }
voltan commented 11 years ago

I think we need date standard on all modules, if any one change calendar or date format , if php extensions installed use that. and if not installed use date()

taiwen commented 11 years ago

The problem is that arguments are different

voltan commented 11 years ago

Perhaps whit this edit is solve :

    /**
     * Locale-dependent formatting/parsing of date-time using pattern strings and/or canned patterns
     *
     * @param array|string|null $locale
     * @param int|null $datetype
     * @param int|null $timetype
     * @param string|null $timezone
     * @param int|string|null $calendar
     * @param string|null $pattern
     * @return string
     */
    function _date($value, $locale = null, $datetype = null, $timetype = null, $timezone = null, $calendar = null, $pattern = null)
    {
        if (!_intl()) {
               $pattern = Pi::config('date_pattern', 'intl');
            return date($value, $pattern);
        }

        $formatter = Pi::service('i18n')->getDateFormatter($locale, $datetype, $timetype, $timezone, $calendar, $pattern);
        $result = $formatter->format($value);

        return $result;
    }

Big thanks for add this option, All of our problems for localization solved