The attached patch adds one t() call to enable translators to translate the suffixes (MB, GB, etc).

It got lost in the replacement code as found in http://drupal.org/node/151902 and was reported by kkaefer.

Comments

damien tournoud’s picture

Well... no.

First we need to put as much as possible context in each translatable string. Just 'GB' is a too small string not to collide with other strings in different contexts (for what I know, it could mean Great Britain...), and to be correctly translatable to every language on the planet. We need to make sure that the full "@size GB" is translated.

Second, you should avoid using t() with a dynamically generated string, because it is harder for the extractor to get all possible combinations (it has to be hard coded in that case).

So:

  • either you find a way to prettily translate each "@size KB", "@size MB", "@size GB", ... (for example by putting a huge select with redundant t()s in your code, but ok, that's not pretty)
  • or you translate "@size " . $suffix (with no wildcard remplacement), and you provide a patch against potx for the strings to be extracted correctly
kkaefer’s picture

The way this worked before is that there was a special statement in the potx.module (which creates the translation templates) which adds the size prefixes to the source string pool. But I agree with Damien in that it’s better to provide context with such short abbreviations. I suggest using return t('@size ' . $suffix, array('@size' => round($size, 2)), $langcode); and patching potx.module to include strings like ‘@size KB’, ‘@size MB’ and so on.

damien tournoud’s picture

@kkaefer#2: that's exacly my suggestion number 2 in #1 above, but thanks for agreeing.

I was thinking, is it possible that some languages would require to change the symbol depending on @size (ie. do we need to pass this thru format_plural()) ?

damien tournoud’s picture

StatusFileSize
new1.98 KB

Here is a solution to this problem. I chose to go the easiest way: remove the loop and treat units one by one. The resulting code is redundant, but is easily translatable and should be efficient.

All CommonFormatSizeTestCase tests pass before and after this patch.

mrharolda’s picture

StatusFileSize
new1.27 KB

Yeah, that's probably a lot more efficient than the workaround I had laying over here:

$units = array(
  t('@size KB', array(), $langcode),
  t('@size MB', array(), $langcode),
  t('@size GB', array(), $langcode),
  t('@size TB', array(), $langcode),
  t('@size PB', array(), $langcode),
  t('@size EB', array(), $langcode),
  t('@size ZB', array(), $langcode),
  t('@size YB', array(), $langcode),
);

and
return str_replace('@size', round($size, 2), $suffix);

dries’s picture

Version: 7.x-dev » 6.x-dev
Status: Needs review » Reviewed & tested by the community

I believe this needs to be backported to Drupal 6. Given that Gabor was closely involved with this code in the Drupal 6 development cycle, I'll let him do another review, and do the final commit. Thanks all! Changing the status and the version number.

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Needs work

Well, does not apply to 6.x since 6.x only supports KB and MB, it has no support for the bigger units. It has the '1 byte' and '@count bytes' quite right, but could use improvement with the KB and MB parts.

function 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);
    }
    return t('@size @suffix', array('@size' => $size, '@suffix' => $suffix), $langcode);
  }
}

Either the suggested '@size KB', '@size MB' change should be ported to 6.x or the whole bigger size handling from 7.x. I am fine with either.

dpearcefl’s picture

Status: Needs work » Postponed (maintainer needs more info)

Is this issue fixed in the latest D6? is there any interest in pursuing this issue?

dpearcefl’s picture

Status: Postponed (maintainer needs more info) » Needs work

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.