function ical_ordinalize_words($i)
{
    if ($i == 1) {
        return __('the first', 'amr-ical-events-list');
    } else {
        if ($i == 0) {
            return __('every', 'amr-ical-events-list');
        } else {
            if ($i == -1) {
                return __('the last', 'amr-ical-events-list');
            } else {
                if ($i < 0) {
                    return sprintf(__('the %s last', 'amr-ical-events-list'), ical_ordinalize(-$i));
                } else {
                    return sprintf(__('the %s', 'amr-ical-events-list'), ical_ordinalize($i));
                }
            }
        }
    }
}
function amr_prettyprint_rule($rule)
{
    /* rrule or exrule */
    /* Receive an array of prepared fields and combine it into a suitable descriptive string */
    global $amr_freq, $amr_freq_unit, $amr_day_of_week_no, $wp_locale;
    $sep = '&nbsp;';
    $c = '';
    if (isset($rule['FREQ'])) {
        $nicefrequnit = $amr_freq_unit[$rule['FREQ']];
        /* already translated value */
        if (isset($rule['INTERVAL'])) {
            /*   the freq as it is repetitive */
            $interval = ' ' . sprintf(__('Every %s %s', 'amr-ical-events-list'), ical_ordinalize($rule['INTERVAL']), $nicefrequnit) . $sep;
        } else {
            $interval = $amr_freq[$rule['FREQ']];
        }
        /* already translated value */
        if (isset($rule['BYSETPOS'])) {
            $c .= ' ' . sprintf(__('On %s instance within %s', 'amr-ical-events-list'), amr_prettyprint_byordinal($rule['BYSETPOS']), $interval);
        } else {
            $c .= $interval;
        }
        if (isset($rule['COUNT'])) {
            $c .= ' ' . sprintf(__('%s times', 'amr-ical-events-list'), $rule['COUNT']) . $sep;
        }
        if (isset($rule['UNTIL'])) {
            if ($rule['UNTIL-TIME'] === '00:00') {
                $rule['UNTIL-TIME'] = '';
            } else {
                if (strtolower($rule['UNTIL-TIME']) === '12:00 am') {
                    $rule['UNTIL-TIME'] = '';
                }
            }
            $c .= '&nbsp;' . sprintf(__('until %s %s', 'amr-ical-events-list'), $rule['UNTIL-DATE'], $rule['UNTIL-TIME']) . $sep;
        }
        if (isset($rule['MONTH'])) {
            $c .= sprintf(__(' if month is %s', 'amr-ical-events-list'), amr_prettyprint_bymonth($rule['MONTH']));
        }
        //		if (isset($rule['BYWEEKNO'])) $c .= ' '.sprintf(__(' in weeks %s','amr-ical-events-list'),implode(',',$rule['BYWEEKNO']));
        if (isset($rule['BYWEEKNO'])) {
            $c .= ' ' . sprintf(__(' in %s weeks of the year', 'amr-ical-events-list'), amr_prettyprint_byordinal($rule['BYWEEKNO']));
        }
        //		if (isset($rule['BYYEARDAY'])) $c .= ' '.sprintf(__('on the %s day of year','amr-ical-events-list'),implode(',',$rule['BYYEARDAY']));
        if (isset($rule['BYYEARDAY'])) {
            $c .= ' ' . sprintf(__('on %s day of the year', 'amr-ical-events-list'), amr_prettyprint_byordinal($rule['BYYEARDAY']));
        }
        if (isset($rule['DAY'])) {
            $c .= ' ' . sprintf(__('on %s day of each month', 'amr-ical-events-list'), amr_prettyprint_byordinal($rule['DAY']));
        }
        if (isset($rule['NBYDAY'])) {
            $nbyday = ' ' . sprintf(__('on %s ', 'amr-ical-events-list'), amr_prettyprint_byday($rule['NBYDAY']));
        }
        if (isset($rule['BYDAY'])) {
            $byday = ' ' . sprintf(__('on %s ', 'amr-ical-events-list'), amr_prettyprint_byday($rule['BYDAY']));
        }
        $ofthefreq = '';
        // change to accomodate dutch having different artcles for month and year de or het
        if ($rule['FREQ'] == 'MONTHLY') {
            $ofthefreq = _x(' of the month', 'eg: last day of the month', 'amr-ical-events-list');
        } else {
            if ($rule['FREQ'] == 'YEARLY') {
                $ofthefreq = _x(' of the year', 'eg: last day of the year', 'amr-ical-events-list');
            }
        }
        if (isset($nbyday) and isset($byday)) {
            $c .= $nbyday . __(' and ', 'amr-ical-events-list') . $byday . $ofthefreq;
        } else {
            if (isset($byday)) {
                $c .= $byday . $ofthefreq;
            }
            if (isset($nbyday)) {
                $c .= $nbyday . $ofthefreq;
            }
        }
        if (isset($rule['BYHOUR'])) {
            $c .= ' ' . sprintf(__('at the %s hour', 'amr-ical-events-list'), implode(',', $rule['BYHOUR']));
        }
        if (isset($rule['BYMINUTE'])) {
            $c .= ' ' . sprintf(__('at the %s minute', 'amr-ical-events-list'), implode(',', $rule['BYMINUTE']));
        }
        if (isset($rule['BYSECOND'])) {
            $c .= ' ' . sprintf(__('at the %s second', 'amr-ical-events-list'), implode(',', $rule['BYSECOND']));
        }
        if (isset($rule['WKST'])) {
            $c .= '; ' . amr_prettyprint_weekst($rule['WKST']);
        }
    }
    return rtrim($c, ',');
}