Skip to content

Commit 0a09bc2

Browse files
eemeliaphillips
andauthored
Add Bidirectional Isolation section to formatting (#315)
* Add "Bidirectional Isolation" section to formatting * Update spec/formatting.md Co-authored-by: Addison Phillips <[email protected]> --------- Co-authored-by: Addison Phillips <[email protected]>
1 parent eedee2f commit 0a09bc2

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

spec/formatting.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,65 @@ when * {Other match}
274274

275275
4. The pattern `{Exact match}` of the most preferred `1` variant is selected.
276276

277+
## Handling Bidirectional Text
278+
279+
_Messages_ contain text which can be bidirectional, that is
280+
consisting of a mixture of left-to-right and right-to-left spans of text.
281+
282+
When concatenating formatted values,
283+
the [Unicode Bidirectional Algorithm](http://www.unicode.org/reports/tr9/) [UAX9]
284+
can produce unexpected or undesirable effects, such as "spillover".
285+
Formatted values SHOULD be bidirectionally isolated
286+
so that the directionality of a formatted _expression_
287+
does not negatively affect the presentation of the overall formatted result.
288+
289+
An implementation MUST define methods for
290+
determining the directionality of the message as a whole as well as each formatted _expression_.
291+
The method of determining the directionality of a formatted _expression_
292+
MAY rely on the introspection of its contents, or on other means.
293+
294+
If a formatted _expression_ itself contains spans with differing directionality,
295+
its formatter SHOULD isolate such parts to avoid
296+
negatively affecting the presentation of the overall formatted result.
297+
298+
> For example, an implementation could provide a `:number` formatting function
299+
> which would always produce output matching the message's locale,
300+
> allowing for its formatted string representation to never need isolation.
301+
302+
Implementations formatting messages as a concatenated string or a sequence of strings
303+
MUST provide one or more strategies for bidirectional isolation.
304+
One such strategy MUST behave as follows:
305+
306+
1. Let `msgdir` be the directionality of the whole message,
307+
one of « `'LTR'`, `'RTL'`, `'unknown'` ».
308+
These correspond to the message having left-to-right directionality,
309+
right-to-left directionality, and to the message's directionality not being known.
310+
1. For each _expression_ `exp` in _pattern_:
311+
1. Let `fmt` be the formatted string representation of the resolved value of `exp`.
312+
1. Let `dir` be the directionality of `fmt`,
313+
one of « `'LTR'`, `'RTL'`, `'unknown'` », with the same meanings as for `msgdir`.
314+
1. If `dir` is `'unknown'`:
315+
1. In the formatted output,
316+
prefix `fmt` with U+2068 FIRST STRONG ISOLATE
317+
and postfix it with U+2069 POP DIRECTIONAL ISOLATE.
318+
1. Else, if `dir` is `'LTR'` and `msgdir` is not `'LTR'`:
319+
1. In the formatted output,
320+
prefix `fmt` with U+2066 LEFT-TO-RIGHT ISOLATE
321+
and postfix it with U+2069 POP DIRECTIONAL ISOLATE.
322+
1. Else, if `dir` is `'RTL'` and `msgdir` is not `'RTL'`:
323+
1. In the formatted output,
324+
prefix `fmt` with U+2067 RIGHT-TO-LEFT ISOLATE
325+
and postfix it with U+2069 POP DIRECTIONAL ISOLATE.
326+
327+
Alternatives to this "compatibility" strategy MAY be provided by implementations,
328+
which MAY also introspect the _pattern_'s _text_ values
329+
and identify situations where isolate characters are not needed
330+
or where additional or different isolation would produce better results.
331+
332+
If an implementation provides formatting to non-string targets,
333+
it SHOULD provide similar strategies for enabling bidirectional isolation,
334+
where appropriate.
335+
277336
## Error Handling
278337

279338
Errors in messages and their formatting may occur and be detected

0 commit comments

Comments
 (0)