message-format-wg icon indicating copy to clipboard operation
message-format-wg copied to clipboard

[FEEDBACK] add `:number` offset option

Open macchiati opened this issue 11 months ago • 9 comments

I investigated using a mock implementation, and there is nothing really standing in the way of adding an offset option to :number. This could be done as an icu:offset option, but it should be noted that one wouldn't be able to have MF1 compatibility without something like it.

The key to implementing is that:

  • The formatting is done with the offset applied.
  • The matching is done depending on the type of key:
    • for literals the offset is not applied.
    • for plural/ordinal categories the offset is applied.

This only required the addition of a few lines of code.

I compared against the equivalent MF1 pattern. Note that MF1 has the special # symbol to indicate the formatted value with offset applied: that just turned into a regular placeholder. Here are the results.

MF1 Pattern:

	{gender_of_host, select, 
	 female {
	  {num_guests, plural, offset:1 
	   =0 {{host} does not give a party.}
	   =1 {{host} invites {guest} to her party.}
	   =2 {{host} invites {guest} and one other person to her party.}
	   other {{host} invites {guest} and # other people to her party.}}}
	 male {
	  {num_guests, plural, offset:1 
	   =0 {{host} does not give a party.}
	   =1 {{host} invites {guest} to his party.}
	   =2 {{host} invites {guest} and one other person to his party.}
	   other {{host} invites {guest} and # other people to his party.}}}
	 other {
	  {num_guests, plural, offset:1 
	   =0 {{host} does not give a party.}
	   =1 {{host} invites {guest} to their party.}
	   =2 {{host} invites {guest} and one other person to their party.}
	   other {{host} invites {guest} and # other people to their party.}}}}

MF2Pattern:

	.input {$num_guests :number u:offset=1}
	.match {$gender_of_host}{$num_guests}
	 female 0 {{{$host} does not give a party.}}
	 female 1 {{{$host} invites {$guest} to her party.}}
	 female 2 {{{$host} invites {$guest} and one other person to her party.}}
	 female * {{{$host} invites {$guest} and {$num_guests} other people to her party.}}
	 male 0 {{{$host} does not give a party.}}
	 male 1 {{{$host} invites {$guest} to his party.}}
	 male 2 {{{$host} invites {$guest} and one other person to his party.}}
	 male * {{{$host} invites {$guest} and {$num_guests} other people to his party.}}
	 * 0 {{{$host} does not give a party.}}
	 * 1 {{{$host} invites {$guest} to their party.}}
	 * 2 {{{$host} invites {$guest} and one other person to their party.}}
	 * * {{{$host} invites {$guest} and {$num_guests} other people to their party.}}

Test results:

OK with input: {$gender_of_host=female, $guest=Mike, $host=Sarah, $num_guests=0}
	MF1: Sarah does not give a party.
	MF2: Sarah does not give a party.
OK with input: {$gender_of_host=female, $guest=Mike, $host=Sarah, $num_guests=1}
	MF1: Sarah invites Mike to her party.
	MF2: Sarah invites Mike to her party.
OK with input: {$gender_of_host=female, $guest=Mike, $host=Sarah, $num_guests=2}
	MF1: Sarah invites Mike and one other person to her party.
	MF2: Sarah invites Mike and one other person to her party.
OK with input: {$gender_of_host=female, $guest=Mike, $host=Sarah, $num_guests=3}
	MF1: Sarah invites Mike and 2 other people to her party.
	MF2: Sarah invites Mike and 2 other people to her party.

macchiati avatar Mar 03 '24 01:03 macchiati