[FEEDBACK] Implementing u:dir
is a little bit tricky
#918
Labels
documentation
Improvements or additions to documentation
Preview-Feedback
Feedback gathered during the technical preview
This issue isn't anything actionable on the spec, I just wanted to highlight this matter to other implementers. Hence, ping @catamorphism, @mihnita, @lucacasonato, @janishorsts.
In short, we have two directionalities that may be set implicitly or explicitly:
These have an effect on our handling of bidirectional text, which includes this requirement:
When you get around to implementing this, there are a few aspects that it took me a while to puzzle through, and I hope that pointing these out may save you some time:
Unless you're implementing some more complicated bidi strategies than the default one and the
'none'
strategy that's added to the test suite in #917, the only place where the message directionality actually matters is that if it's LTR and a placeholder has LTR directionality, then it doesn't need to be isolated.While the
u:locale
override definitely matters for the formatted value of a placeholder, theu:dir
doesn't. It's only overriding the directionality of the placeholder in the context of the message.We have not defined well how the directionality of placeholders with standard annotations like
:number
or:datetime
is determined. I opted to detect it from the locale, unless overridden byu:dir
.Your function context and resolved value will need directionality indicators with four possible values: LTR, RTL, auto, and undefined (because an expression with
u:dir=auto
can be in a variable declaration that's then used as an operand). For formatted parts (if implementing), auto and undefined can collapse into a single value.With the default bidi strategy, a message like
Hello {world}
gets formatted in English as'Hello \u2068world\u2069'
(i.e. with FSI/PDI isolates), unless you introspect the value and discover that it's definitely LTR. You may be tempted therefore to do that introspection. Before you do, consider whether that makes any sense: Aren't you just front-loading work that would get done by the rendering engine in any case? And isn't your rendering engine rather likely to be well optimized for exactly that task? Don't be like me, as I wrote a hacky version of UAX#9 P2 in JS (which doesn't support\p{Bidi_Class=...}
in regexps) before I realised that I don't need one, and threw it away.The text was updated successfully, but these errors were encountered: