Get the locale info returned by localeconv(), but cache it, to
avoid repeated calls.
public static getLocaleInfo ( ) : array | ||
return | array | The results of localeconv(). |
/** */ protected function _getValidationPattern() { static $pattern = ''; if (!empty($pattern)) { return $pattern; } /* Get current locale information. */ $linfo = Horde_Nls::getLocaleInfo(); /* Build the pattern. */ $pattern = '(-)?'; /* Only check thousands separators if locale has any. */ if (!empty($linfo['mon_thousands_sep'])) { /* Regex to check for correct thousands separators (if any). */ $pattern .= '((\\d+)|((\\d{0,3}?)([' . $linfo['mon_thousands_sep'] . ']\\d{3})*?))'; } else { /* No locale thousands separator, check for only digits. */ $pattern .= '(\\d+)'; } /* If no decimal point specified default to dot. */ if (empty($linfo['mon_decimal_point'])) { $linfo['mon_decimal_point'] = '.'; } /* Regex to check for correct decimals (if any). */ if (empty($this->_fraction)) { $fraction = '*'; } else { $fraction = '{0,' . $this->_fraction . '}'; } $pattern .= '([' . $linfo['mon_decimal_point'] . '](\\d' . $fraction . '))?'; /* Put together the whole regex pattern. */ $pattern = '/^' . $pattern . '$/'; return $pattern; }
function _renderVarInput_number($form, $var, $vars) { $value = $var->getValue($vars); if ($var->type->fraction) { $value = sprintf('%01.' . $var->type->fraction . 'f', $value); } $linfo = Horde_Nls::getLocaleInfo(); /* Only if there is a mon_decimal_point do the * substitution. */ if (!empty($linfo['mon_decimal_point'])) { $value = str_replace('.', $linfo['mon_decimal_point'], $value); } return sprintf(' <input type="text" class="form-input-number" name="%1$s" id="%1$s" value="%2$s"%3$s />', $var->getVarName(), $value, $this->_getActionScripts($form, $var)); }
protected function _renderVarInput_number($form, &$var, &$vars) { $value = $var->getValue($vars); if ($var->type->getProperty('fraction')) { $value = sprintf('%01.' . $var->type->getProperty('fraction') . 'f', $value); } $linfo = Horde_Nls::getLocaleInfo(); /* Only if there is a mon_decimal_point do the * substitution. */ if (!empty($linfo['mon_decimal_point'])) { $value = str_replace('.', $linfo['mon_decimal_point'], $value); } return sprintf('<input type="text" size="5" name="%s" id="%s" value="%s"%s />', htmlspecialchars($var->getVarName()), $this->_genID($var->getVarName(), false), $value, $this->_getActionScripts($form, $var)); }
function getInfo(&$vars, &$var, &$info) { $value = $vars->get($var->getVarName()); $linfo = Horde_Nls::getLocaleInfo(); $value = str_replace($linfo['mon_thousands_sep'], '', $value); $info = str_replace($linfo['mon_decimal_point'], '.', $value); }
/** * Workaround broken number_format() prior to PHP 5.4.0. * * @param integer $number Number to format. * @param integer $decimals Number of decimals to display. * * @return string See number_format(). */ public static function numberFormat($number, $decimals) { $localeinfo = Horde_Nls::getLocaleInfo(); return str_replace(array('X', 'Y'), array($localeinfo['decimal_point'], $localeinfo['thousands_sep']), number_format($decimals ? $number : ceil($number), $decimals, 'X', 'Y')); }
/** * Output the size of this MIME part in KB. * * @todo Remove $approx parameter. * * @param boolean $approx If true, determines an approximate size for * parts consisting of base64 encoded data. * * @return string Size of the part in KB. */ public function getSize($approx = false) { if (!($bytes = $this->getBytes($approx))) { return 0; } $localeinfo = Horde_Nls::getLocaleInfo(); // TODO: Workaround broken number_format() prior to PHP 5.4.0. return str_replace(array('X', 'Y'), array($localeinfo['decimal_point'], $localeinfo['thousands_sep']), number_format(ceil($bytes / 1024), 0, 'X', 'Y')); }
/** * Output the size of this MIME part in KB. * * @param boolean $approx If true, determines an approximate size for * parts consisting of base64 encoded data. * * @return string Size of the part in KB. */ public function getSize($approx = false) { if (!($bytes = $this->getBytes($approx))) { return 0; } $kb = $bytes / 1024; $localeinfo = Horde_Nls::getLocaleInfo(); /* Reduce need for decimals as part size gets larger. */ if ($kb > 100) { $decimals = 0; } elseif ($kb > 10) { $decimals = 1; } else { $decimals = 2; } // TODO: Workaround broken number_format() prior to PHP 5.4.0. return str_replace(array('X', 'Y'), array($localeinfo['decimal_point'], $localeinfo['thousands_sep']), number_format($kb, $decimals, 'X', 'Y')); }