Problem/Motivation

When using the number field, eg. with the decimal formatter, and adding a prefix and suffix, the prefix and suffix do not get translated.

Proposed resolution

In code, the number.module uses the format_plural()-function to format multiple prefixes and suffixes. For single prefix/suffix, it simply returns the prefix/suffix value. There should be a t-function on that value.

Code in number.module, line 298:

Original code:

$prefix = (count($prefixes) > 1) ? format_plural($item['value'], $prefixes[0], $prefixes[1]) : $prefixes[0];
$suffix = (count($suffixes) > 1) ? format_plural($item['value'], $suffixes[0], $suffixes[1]) : $suffixes[0];

Code in attached patch:

$prefix = (count($prefixes) > 1) ? format_plural($item['value'], $prefixes[0], $prefixes[1]) : t($prefixes[0]);
$suffix = (count($suffixes) > 1) ? format_plural($item['value'], $suffixes[0], $suffixes[1]) : t($suffixes[0]);

Remaining tasks

Verify and commit patch to core dev-channel.

Comments

avr’s picture

Version: 7.14 » 8.x-dev
Issue tags: +Needs backport to D7
StatusFileSize
new1.27 KB

Rerolled for Drupal 8.

gábor hojtsy’s picture

Status: Needs review » Closed (won't fix)

The format_plural()'s presence in itself is a bug. User provided data should not be translated with t(), if you look at the field label, etc. are not translated either. See #1664272: Singular prefix/suffix on number field do not get translated. for removing the format_plural from there.

tim.plunkett’s picture

gábor hojtsy’s picture

Yes, that one, clipboard error :)