1

The pattern }}}}123 is valid syntax in ICU DecimalFormat, because } is in the legal range for a padding character. This can be validated in PHP as follows:

$f = new NumberFormatter('en_GB', NumberFormatter::PATTERN_DECIMAL, '*}######0');
$this->assertSame('}}}}123', $f->format(123));
                   -------
                   correct

But embedding this in ICU MessageFormat, we have the problem that the brace character ends the argument prematurely and would need escaping.

Again, using PHP to verify that this throws IntlException:

$f = new MessageFormatter('en_GB', "{0,number,*}######0}");
$this->assertSame('}}}}123', $f->format([123]));

Quoting the format according to ICU MessageFormat syntax doesn't work either, because a quote symbol is an invalid padChar in the DecimalFormat grammar. In summary, none of these work:

  • {0,number,*}######0}
  • {0,number,*'}'######0}
  • {0,number,'*}######0'}

It seems that the DecimalFormat syntax is not compatible with MessageFormat's argStyleText syntax.

Is this a bug in PHP's Intl extension, or is there a way to escape the decimal pattern in messages?

Please note that this is an academic question about ICU MessageFormat, I am not asking how to pad an integer in PHP.

Tim
  • 8,036
  • 2
  • 36
  • 52
  • Read this: https://stackoverflow.com/a/31122089/454827 – ZiTAL Oct 11 '18 at 13:11
  • What are you suggesting? My example is not production code, and I am not using PHP's assert function. – Tim Oct 11 '18 at 14:21
  • Sorry I think I don't understand your question... maybe you have a problem with last "}", I think you need to open the first "{" to close with the final "}", something like this: ```{{0,number,*}######0}``` – ZiTAL Oct 11 '18 at 14:53
  • This is not correct and you don't seem to be familiar with ICU MessageFormat syntax – Tim Oct 11 '18 at 15:29

0 Answers0