Skip to content

Commit f969ab6

Browse files
committed
Add Unicode Registry definition
1 parent 0117fee commit f969ab6

File tree

6 files changed

+194
-3
lines changed

6 files changed

+194
-3
lines changed

spec/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
1. [Resolution Errors](errors.md#resolution-errors)
1818
1. [Message Function Errors](errors.md#message-function-errors)
1919
1. [Default Function Registry](registry/default.md)
20+
1. [`u:` Unicode Registry](registry/unicode.md)
2021
1. [Formatting](formatting.md)
2122
1. [Interchange data model](data-model/README.md)
2223

spec/formatting.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,21 @@ the following steps are taken:
214214
215215
3. Perform _option resolution_.
216216
217-
4. Call the function implementation with the following arguments:
217+
4. Determine the **_<dfn>function context</dfn>_** for calling the function implementation.
218+
This includes:
218219
219-
- The current _locale_.
220+
- The current _locale_,
221+
potentially including a fallback chain of locales.
222+
- The base directionality of the _message_ and its _text_ tokens.
223+
224+
If the resolved mapping of _options_ includes any `u:` options
225+
supported by the implementation,
226+
process them as specified in the [Unicode Registry](/spec/registry/unicode.md).
227+
Such `u:` options MAY be removed from the resolved mapping of _options_.
228+
229+
5. Call the function implementation with the following arguments:
230+
231+
- The _function context_.
220232
- The resolved mapping of _options_.
221233
- If the _expression_ includes an _operand_, its resolved value.
222234
@@ -303,7 +315,7 @@ the following steps are taken:
303315
304316
Implementation-defined _functions_ SHOULD use an implementation-defined _namespace_.
305317
306-
5. If the call succeeds,
318+
6. If the call succeeds,
307319
resolve the value of the _expression_ as the result of that function call.
308320
309321
If the call fails or does not return a valid value,
@@ -344,6 +356,11 @@ The resolved value of _markup_ includes the following fields:
344356
- The _identifier_ of the _markup_
345357
- The resolved _options_ values after _option resolution_.
346358
359+
If the resolved mapping of _options_ includes any `u:` options
360+
supported by the implementation,
361+
process them as specified in the [Unicode Registry](/spec/registry/unicode.md).
362+
Such `u:` options MAY be removed from the resolved mapping of _options_.
363+
347364
The resolution of _markup_ MUST always succeed.
348365
349366
### Fallback Resolution

spec/registry/unicode.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# MessageFormat 2.0 Unicode Registry
2+
3+
The `u:` namespace is reserved for use by the Unicode Consortium.
4+
5+
## Options
6+
7+
This section describes common options which each implementation SHOULD support
8+
for all _functions_ and _markup_.
9+
10+
### `u:id`
11+
12+
A string value that is included as an `id` or other suitable value
13+
in the formatted parts for the _placeholder_,
14+
or any other structured formatted results.
15+
16+
Ignored when formatting a message to a string.
17+
18+
Accepts string values, or values which can be stringified without error.
19+
For other values, a _Bad Option_ error is emitted
20+
and the `u:id` option is ignored.
21+
22+
### `u:locale`
23+
24+
A comma-delimited list of BCP 47 language tags,
25+
or an implementation-defined list of such tags.
26+
27+
Replaces the _locale_ defined in the _function context_ for this _expression_.
28+
The value is ignored when set on _markup_.
29+
30+
During processing, the `u:locale` option
31+
is always removed from the resolved mapping of _options_.
32+
33+
Values matching the following ABNF are always accepted:
34+
```abnf
35+
u-locale-option = langtag *([s] "," [s] langtag)
36+
```
37+
using `langtag` as defined in [RFC 5646](https://www.rfc-editor.org/rfc/rfc5646).
38+
39+
Implementations MAY support additional language tags,
40+
such as private-use or grandfathered tags,
41+
or tags using `_` instead of `-` as a separator.
42+
When the value of `u:locale` is set by a _variable_,
43+
implementations MAY support non-string values otherwise representing locales.
44+
45+
For unsupported values, a _Bad Option_ error is emitted
46+
and the value of the `u:locale` option is ignored.
47+
48+
### `u:dir`
49+
50+
Replaces the base directionality defined in
51+
the _function context_ for this _expression_.
52+
The value is ignored when set on _markup_.
53+
54+
During processing, the `u:dir` option
55+
is always removed from the resolved mapping of _options_.
56+
57+
Accepts the following string values:
58+
- `ltr`: left-to-right directionality
59+
- `rtl`: right-to-left directionality
60+
- `auto`: directionality determined from _expression_ contents
61+
62+
For other values, a _Bad Option_ error is emitted
63+
and the value of the `u:dir` option is ignored.

test/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ These test files are intended to be useful for testing multiple different messag
1010
- `data-model-errors.json` - Strings that should produce Data Model Error when processed.
1111
Error names are defined in ["MessageFormat 2.0 Errors"](../spec/errors.md) in the spec.
1212

13+
- `unicode.md` — Test cases for the `u:` Unicode Registry, using built-in functions.
14+
1315
- `functions/` — Test cases that correspond to built-in functions.
1416
The behaviour of the built-in formatters is implementation-specific so the `exp` field is often
1517
omitted and assertions are made on error cases.

test/schemas/v0/tests.schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@
269269
"name": {
270270
"type": "string"
271271
},
272+
"id": {
273+
"type": "string"
274+
},
272275
"options": {
273276
"type": "object"
274277
}

test/tests/unicode.json

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/unicode-org/message-format-wg/main/test/schemas/v0/tests.schema.json",
3+
"scenario": "Unicode u: Registry",
4+
"description": "Common options affecting the function context",
5+
"defaultTestProperties": {
6+
"locale": "en-US"
7+
},
8+
"tests": [
9+
{
10+
"src": "{#tag u:id=x u:dir=rtl u:locale=ar}content{/ns:tag u:id=x}",
11+
"exp": "content",
12+
"expParts": [
13+
{
14+
"type": "markup",
15+
"kind": "open",
16+
"id": "x",
17+
"name": "tag"
18+
},
19+
{
20+
"type": "literal",
21+
"value": "content"
22+
},
23+
{
24+
"type": "markup",
25+
"kind": "close",
26+
"id": "x",
27+
"name": "tag"
28+
}
29+
]
30+
},
31+
{
32+
"src": "hello {4.2 :number u:locale=fr}",
33+
"exp": "hello 4,2"
34+
},
35+
{
36+
"src": "hello {world :string u:dir=ltr u:id=foo}",
37+
"exp": "hello world",
38+
"expParts": [
39+
{
40+
"type": "literal",
41+
"value": "hello "
42+
},
43+
{
44+
"type": "string",
45+
"source": "|world|",
46+
"dir": "ltr",
47+
"id": "foo",
48+
"value": "world"
49+
}
50+
]
51+
},
52+
{
53+
"src": "hello {world :string u:dir=rtl}",
54+
"exp": "hello \u2067world\u2069",
55+
"expParts": [
56+
{
57+
"type": "literal",
58+
"value": "hello "
59+
},
60+
{
61+
"type": "string",
62+
"source": "|world|",
63+
"dir": "rtl",
64+
"value": "world"
65+
}
66+
]
67+
},
68+
{
69+
"src": "hello {world :string u:dir=auto}",
70+
"exp": "hello \u2068world\u2069",
71+
"expParts": [
72+
{
73+
"type": "literal",
74+
"value": "hello "
75+
},
76+
{
77+
"type": "string",
78+
"source": "|world|",
79+
"dir": "auto",
80+
"value": "world"
81+
}
82+
]
83+
},
84+
{
85+
"locale": "ar",
86+
"src": "أهلاً {بالعالم :string u:dir=rtl}",
87+
"exp": "أهلاً \u2067بالعالم\u2069"
88+
},
89+
{
90+
"locale": "ar",
91+
"src": "أهلاً {بالعالم :string u:dir=auto}",
92+
"exp": "أهلاً \u2068بالعالم\u2069"
93+
},
94+
{
95+
"locale": "ar",
96+
"src": "أهلاً {world :string u:dir=ltr}",
97+
"exp": "أهلاً \u2066world\u2069"
98+
},
99+
{
100+
"locale": "ar",
101+
"src": "أهلاً {بالعالم :string}",
102+
"exp": "أهلاً \u2067بالعالم\u2069"
103+
}
104+
]
105+
}

0 commit comments

Comments
 (0)