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

Allow leading and trailing whitespace in complex messages

Open lucacasonato opened this issue 1 year ago • 4 comments

Currenly, complex messages can not start or end with whitespace. The first character of a complex message must either be . or {, and the final character must be }. This is unfortunate, because this results in unnecessary complexity for users.

Example:

const message = `
.input {$count :number}
.match {$count}
one {{You have {$count} notification.}}
*   {{You have {$count} notifications.}}
`

This does not work right now, because there is whitespace between the string start, and the first char of the complex message, and the trailing } and the end of the string.

This can not be remedied by just trimming all messages, because for simple messages, leading and trailing whitespace is significant.

For complex messages, leading and trailing whitespace is not significant, because all chars outside of a quoted-pattern are control characters and not relevant for display (they are not included in the output message).

To fix this, complex-message grammar can be changed as follows:

- complex-body = quoted-pattern / matcher
+ complex-body = [s] (quoted-pattern / matcher) [s]

lucacasonato avatar Jun 15 '24 19:06 lucacasonato

See https://github.com/unicode-org/message-format-wg/blob/main/exploration/pattern-exterior-whitespace.md for previous discussion on this.

catamorphism avatar Jun 18 '24 23:06 catamorphism

I am not sure how relevant that discussion is, as it focuses on trimming white space around unquoted patterns (like simple message). I however am only concerned about complex messages here, which can not contain unquoted patterns. Additionally the spec already agrees that quotes before quoted patterns are not meaningful: for example, the optional space between key and quoted-pattern in variant shows this. I'm suggesting this is white space allowance is expanded to around the entire complex body.

lucacasonato avatar Jun 19 '24 08:06 lucacasonato

The perhaps more relevant prior discussion is #610, where I hit the same issue.

eemeli avatar Jun 19 '24 08:06 eemeli

With #812 I have added this to the agenda of the 2024-07-01 call. Note that leading whitespace conflicts with simple message processing, as described in the PEWS design document @catamorphism linked above.

aphillips avatar Jul 01 '24 13:07 aphillips

Also see this previous ballot https://github.com/unicode-org/message-format-wg/issues/505 with related discussion thread https://github.com/unicode-org/message-format-wg/issues/507

echeran avatar Jul 29 '24 16:07 echeran

The WG agreed to permit opening and trailing whitespace in complex messages. Waiting to merge #854 to close this issue.

aphillips avatar Aug 09 '24 13:08 aphillips