/** * Localization * @param string $type Type of localization * @param array|int|string $data parameters for this localization * @param array $options * @return string|false * * Returns the localized data. * * Implemented types: * - date * - Creates a date * - params: timestamp (int/string) * - datetime * - Creates date and time * - params: timestamp (int/string) * - time * - Creates a time * - params: timestamp (int/string) */ public function l($type, $data, $options = array()) { if ($type === 'firstday') { return $this->getFirstWeekDay(); } if ($type === 'jsdate') { return $this->getDateFormat(); } $this->init(); $value = new DateTime(); if ($data instanceof DateTime) { $value = $data; } elseif (is_string($data) && !is_numeric($data)) { $data = strtotime($data); $value->setTimestamp($data); } else { $value->setTimestamp($data); } // Use the language of the instance, before falling back to the current user's language $locale = $this->lang; if ($locale === null) { $locale = self::findLanguage(); } $locale = $this->transformToCLDRLocale($locale); $options = array_merge(array('width' => 'long'), $options); $width = $options['width']; switch ($type) { case 'date': return Punic\Calendar::formatDate($value, $width, $locale); case 'datetime': return Punic\Calendar::formatDatetime($value, $width, $locale); case 'time': return Punic\Calendar::formatTime($value, $width, $locale); default: return false; } }
/** * Localization * @param string $type Type of localization * @param array|int|string $data parameters for this localization * @return String or false * * Returns the localized data. * * Implemented types: * - date * - Creates a date * - params: timestamp (int/string) * - datetime * - Creates date and time * - params: timestamp (int/string) * - time * - Creates a time * - params: timestamp (int/string) */ public function l($type, $data, $options = array()) { if ($type === 'firstday') { return $this->getFirstWeekDay(); } if ($type === 'jsdate') { return $this->getDateFormat(); } $this->init(); $value = new DateTime(); if ($data instanceof DateTime) { $value = $data; } elseif (is_string($data) && !is_numeric($data)) { $data = strtotime($data); $value->setTimestamp($data); } else { $value->setTimestamp($data); } $locale = self::findLanguage(); $options = array_merge(array('width' => 'long'), $options); $width = $options['width']; switch ($type) { case 'date': return Punic\Calendar::formatDate($value, $width, $locale); break; case 'datetime': return Punic\Calendar::formatDatetime($value, $width, $locale); break; case 'time': return Punic\Calendar::formatTime($value, $width, $locale); break; default: return false; } }