unicode-org / message-format-wg

Developing a standard for localizable message strings
Other
229 stars 33 forks source link

Allow leading and trailing whitespace in complex messages #809

Closed lucacasonato closed 1 month ago

lucacasonato commented 3 months ago

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]
catamorphism commented 3 months ago

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

lucacasonato commented 3 months ago

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.

eemeli commented 3 months ago

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

aphillips commented 3 months ago

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.

echeran commented 2 months ago

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

aphillips commented 1 month ago

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