@@ -80,101 +80,101 @@ The syntax specification takes into account the following design restrictions:
80
80
81
81
### Simple Messages
82
82
83
- All messages, including simple ones, need ` […] ` delimiters:
83
+ All messages, including simple ones, need ` {…} ` delimiters:
84
84
85
- [ Hello, world!]
85
+ { Hello, world!}
86
86
87
87
The same message defined in a ` .properties ` file:
88
88
89
89
``` properties
90
- app.greetings.hello = [ Hello, world!]
90
+ app.greetings.hello = { Hello, world!}
91
91
```
92
92
93
93
The same message defined inline in JavaScript:
94
94
95
95
``` js
96
- let hello = new MessageFormat (' [ Hello, world!] ' )
96
+ let hello = new MessageFormat (' { Hello, world!} ' )
97
97
hello .format ()
98
98
```
99
99
100
100
### Simple Placeholders
101
101
102
- Messages may contain placeholders within ` {…} ` delimiters,
102
+ Messages may contain placeholders within nested ` {…} ` delimiters,
103
103
such as variables that are expected to be passed in as format paramters:
104
104
105
- [ Hello, {$userName}!]
105
+ { Hello, {$userName}!}
106
106
107
107
### Formatting Functions
108
108
109
109
A message with an interpolated ` $date ` variable formatted with the ` :datetime ` function:
110
110
111
- [ Today is {$date :datetime weekday=long}.]
111
+ { Today is {$date :datetime weekday=long}.}
112
112
113
113
A message with an interpolated ` $userName ` variable formatted with
114
114
the custom ` :person ` function capable of
115
115
declension (using either a fixed dictionary, algorithmic declension, ML, etc.):
116
116
117
- [ Hello, {$userName :person case=vocative}!]
117
+ { Hello, {$userName :person case=vocative}!}
118
118
119
119
A message with an interpolated ` $userObj ` variable formatted with
120
120
the custom ` :person ` function capable of
121
121
plucking the first name from the object representing a person:
122
122
123
- [ Hello, {$userObj :person firstName=long}!]
123
+ { Hello, {$userObj :person firstName=long}!}
124
124
125
125
### Markup Elements
126
126
127
127
A message with two markup-like element placeholders, ` button ` and ` link ` ,
128
128
which the runtime can use to construct a document tree structure for a UI framework.
129
129
130
- [{ +button}Submit{-button} or {+link}cancel{-link}.]
130
+ {{ +button}Submit{-button} or {+link}cancel{-link}.}
131
131
132
132
### Selection
133
133
134
134
A message with a single selector:
135
135
136
136
match {$count :number}
137
- when 1 [ You have one notification.]
138
- when * [ You have {$count} notifications.]
137
+ when 1 { You have one notification.}
138
+ when * { You have {$count} notifications.}
139
139
140
140
A message with a single selector which is an invocation of
141
141
a custom function ` :platform ` , formatted on a single line:
142
142
143
- match {:platform} when windows [ Settings] when * [ Preferences]
143
+ match {:platform} when windows { Settings} when * { Preferences}
144
144
145
145
A message with a single selector and a custom ` :hasCase ` function
146
146
which allows the message to query for presence of grammatical cases required for each variant:
147
147
148
148
match {$userName :hasCase}
149
- when vocative [ Hello, {$userName :person case=vocative}!]
150
- when accusative [ Please welcome {$userName :person case=accusative}!]
151
- when * [ Hello!]
149
+ when vocative { Hello, {$userName :person case=vocative}!}
150
+ when accusative { Please welcome {$userName :person case=accusative}!}
151
+ when * { Hello!}
152
152
153
153
A message with 2 selectors:
154
154
155
155
match {$photoCount :number} {$userGender :equals}
156
- when 1 masculine [{ $userName} added a new photo to his album.]
157
- when 1 feminine [{ $userName} added a new photo to her album.]
158
- when 1 * [{ $userName} added a new photo to their album.]
159
- when * masculine [{ $userName} added {$photoCount} photos to his album.]
160
- when * feminine [{ $userName} added {$photoCount} photos to her album.]
161
- when * * [{ $userName} added {$photoCount} photos to their album.]
156
+ when 1 masculine {{ $userName} added a new photo to his album.}
157
+ when 1 feminine {{ $userName} added a new photo to her album.}
158
+ when 1 * {{ $userName} added a new photo to their album.}
159
+ when * masculine {{ $userName} added {$photoCount} photos to his album.}
160
+ when * feminine {{ $userName} added {$photoCount} photos to her album.}
161
+ when * * {{ $userName} added {$photoCount} photos to their album.}
162
162
163
163
### Local Variables
164
164
165
165
A message defining a local variable ` $whom ` which is then used twice inside the pattern:
166
166
167
167
let $whom = {$monster :noun case=accusative}
168
- [ You see {$quality :adjective article=indefinite accord=$whom} {$whom}!]
168
+ { You see {$quality :adjective article=indefinite accord=$whom} {$whom}!}
169
169
170
170
A message defining two local variables:
171
171
` $itemAcc ` and ` $countInt ` , and using ` $countInt ` as a selector:
172
172
173
173
let $countInt = {$count :number maximumFractionDigits=0}
174
174
let $itemAcc = {$item :noun count=$count case=accusative}
175
175
match {$countInt}
176
- when one [ You bought {$color :adjective article=indefinite accord=$itemAcc} {$itemAcc}.]
177
- when * [ You bought {$countInt} {$color :adjective accord=$itemAcc} {$itemAcc}.]
176
+ when one { You bought {$color :adjective article=indefinite accord=$itemAcc} {$itemAcc}.}
177
+ when * { You bought {$countInt} {$color :adjective accord=$itemAcc} {$itemAcc}.}
178
178
179
179
### Complex Messages
180
180
@@ -186,20 +186,20 @@ A complex message with 2 selectors and 3 local variable definitions:
186
186
187
187
match {$host :gender} {$guestOther :number}
188
188
189
- when female 0 [{ $hostName} does not give a party.]
190
- when female 1 [{ $hostName} invites {$guestName} to her party.]
191
- when female 2 [{ $hostName} invites {$guestName} and one other person to her party.]
192
- when female * [{ $hostName} invites {$guestName} and {$guestsOther} other people to her party.]
189
+ when female 0 {{ $hostName} does not give a party.}
190
+ when female 1 {{ $hostName} invites {$guestName} to her party.}
191
+ when female 2 {{ $hostName} invites {$guestName} and one other person to her party.}
192
+ when female * {{ $hostName} invites {$guestName} and {$guestsOther} other people to her party.}
193
193
194
- when male 0 [{ $hostName} does not give a party.]
195
- when male 1 [{ $hostName} invites {$guestName} to his party.]
196
- when male 2 [{ $hostName} invites {$guestName} and one other person to his party.]
197
- when male * [{ $hostName} invites {$guestName} and {$guestsOther} other people to his party.]
194
+ when male 0 {{ $hostName} does not give a party.}
195
+ when male 1 {{ $hostName} invites {$guestName} to his party.}
196
+ when male 2 {{ $hostName} invites {$guestName} and one other person to his party.}
197
+ when male * {{ $hostName} invites {$guestName} and {$guestsOther} other people to his party.}
198
198
199
- when * 0 [{ $hostName} does not give a party.]
200
- when * 1 [{ $hostName} invites {$guestName} to their party.]
201
- when * 2 [{ $hostName} invites {$guestName} and one other person to their party.]
202
- when * * [{ $hostName} invites {$guestName} and {$guestsOther} other people to their party.]
199
+ when * 0 {{ $hostName} does not give a party.}
200
+ when * 1 {{ $hostName} invites {$guestName} to their party.}
201
+ when * 2 {{ $hostName} invites {$guestName} and one other person to their party.}
202
+ when * * {{ $hostName} invites {$guestName} and {$guestsOther} other people to their party.}
203
203
204
204
## Productions
205
205
@@ -240,15 +240,15 @@ Examples:
240
240
241
241
```
242
242
match {$count :plural}
243
- when 1 [ One apple]
244
- when * [{ $count} apples]
243
+ when 1 { One apple}
244
+ when * {{ $count} apples}
245
245
```
246
246
247
247
```
248
248
let $frac = {$count: number minFractionDigits=2}
249
249
match {$frac}
250
- when 1 [ One apple]
251
- when * [{ $frac} apples]
250
+ when 1 { One apple}
251
+ when * {{ $frac} apples}
252
252
```
253
253
254
254
### Variants
@@ -270,13 +270,13 @@ A well-formed message is considered valid if the following requirements are sati
270
270
### Patterns
271
271
272
272
A pattern is a sequence of translatable elements.
273
- Patterns are always delimited with ` [ ` at the start, and ` ] ` at the end.
273
+ Patterns are always delimited with ` { ` at the start, and ` } ` at the end.
274
274
This serves 3 purposes:
275
275
276
276
- The message should be unambiguously embeddable in various container formats
277
277
regardless of the container's whitespace trimming rules.
278
278
E.g. in Java ` .properties ` files,
279
- ` hello = [ Hello] ` will unambiguously define the ` Hello ` message without the space in front of it.
279
+ ` hello = { Hello} ` will unambiguously define the ` Hello ` message without the space in front of it.
280
280
- The message should be conveniently embeddable in various programming languages
281
281
without the need to escape characters commonly related to strings, e.g. ` " ` and ` ' ` .
282
282
Such need may still occur when a single or double quote is
@@ -285,13 +285,13 @@ This serves 3 purposes:
285
285
are translatable and which ones are part of the formatting logic definition.
286
286
287
287
``` ebnf
288
- Pattern ::= '[ ' (Text | Placeholder)* '] ' /* ws: explicit */
288
+ Pattern ::= '{ ' (Text | Placeholder)* '} ' /* ws: explicit */
289
289
```
290
290
291
291
Examples:
292
292
293
293
```
294
- [ Hello, world!]
294
+ { Hello, world!}
295
295
```
296
296
297
297
### Placeholders
@@ -366,11 +366,11 @@ MarkupEnd ::= '-' Name /* ws: explicit */
366
366
Examples:
367
367
368
368
```
369
- [ This is {+b}bold{-b}.]
369
+ { This is {+b}bold{-b}.}
370
370
```
371
371
372
372
```
373
- [{ +h1 name=(above-and-beyond)}Above And Beyond{-h1}]
373
+ {{ +h1 name=(above-and-beyond)}Above And Beyond{-h1}}
374
374
```
375
375
376
376
## Tokens
@@ -381,13 +381,12 @@ The grammar defines the following tokens for the purpose of the lexical analysis
381
381
382
382
Text is the translatable content of a _ pattern_ .
383
383
Any Unicode codepoint is allowed in text, with the exception of
384
- ` [ ` and ` ] ` (which delimit patterns),
385
- ` { ` and ` } ` (which delimit placeholders),
384
+ ` { ` and ` } ` (which delimit patterns and placeholders),
386
385
and ` \ ` (which starts an escape sequence).
387
386
388
387
``` ebnf
389
388
Text ::= (TextChar | TextEscape)+ /* ws: explicit */
390
- TextChar ::= AnyChar - ('[' | ']' | ' {' | '}' | Esc)
389
+ TextChar ::= AnyChar - ('{' | '}' | Esc)
391
390
AnyChar ::= [#x0-#x10FFFF]
392
391
```
393
392
@@ -449,7 +448,7 @@ They are allowed in translatable text as well as in literals.
449
448
450
449
``` ebnf
451
450
Esc ::= '\'
452
- TextEscape ::= Esc Esc | Esc '[' | Esc ']' | Esc ' {' | Esc '}'
451
+ TextEscape ::= Esc Esc | Esc '{' | Esc '}'
453
452
LiteralEscape ::= Esc Esc | Esc '(' | Esc ')'
454
453
```
455
454
0 commit comments