I'm trying to figure out how to make sure the suffix of a number does not break from the number attached. I am working on the format_size function which I called in my template.php file: caeq_format_size.

Here it goes:

function caeq_format_size($size, $langcode = NULL) {
if ($size < 1024) {
return format_plural($size, '1 byte', '@count bytes', array(), $langcode);
}
else {
$size = round($size / 1024, 2);
$suffix = t('KB', array(), $langcode);
if ($size >= 1024) {
$size = round($size / 1024, 2);
$suffix = t('MB', array(), $langcode);
}
$suffix='_'.$suffix; >>>>> This works.
$suffix='\&nbsp\;'.$suffix; >>>>> This does not work even without the escape sequence.
return t('@size@suffix', array('@size' => $size, '@suffix' => $suffix), $langcode);
}
}

I have tried the !variable format, but to no avail.

Any idea?

Comments

zeta ζ’s picture

If you use this code;

  $suffix = $suffix; // the space is in the format string below.
  return '<span class="atom">' . t('@size @suffix', array('@size' => $size, '@suffix' => $suffix), $langcode) . '</span>'; 

and add the syle;

.atom {
  white-space: nowrap;
}

to your css file
___________________
It’s in the detaιls…

demonstration portfolio

Guy Verville’s picture

Yes! Thank you very much!

http://www.guyverville.com

zeta ζ’s picture

As DamZ pointed out with a patch I recently submitted to core, The data still needs to go through format_plural().
Try this;

function caeq_format_size($size, $langcode = NULL) {
  switch (intval((log($size, 1024))) {
    case 0:
      $output = format_plural($size, '1 byte', '@count bytes', array(), $langcode);
      break;
    case 1:
      $output = format_plural(round($size / 1024, 2), '1 KB', '@count KB', array(), $langcode);
      break;
    case 2:
      $output = format_plural(round($size / 1024 ^ 2, 2), '1 MB', '@count MB', array(), $langcode);
      break;
    case 3:
      $output = format_plural(round($size / 1024 ^ 3, 2), '1 GB', '@count GB', array(), $langcode);
      break;
    case 4:
      $output = format_plural(round($size / 1024 ^ 4, 2), '1 TB', '@count TB', array(), $langcode);
      break;
  }
  return '<span class="atom">' . $output . '</span>';
} 

___________________
It’s in the detaιls…

demonstration portfolio