iD icon indicating copy to clipboard operation
iD copied to clipboard

Bidi tags

Open NeatNit opened this issue 7 months ago • 6 comments

URL

https://master.apis.dev.openstreetmap.org/edit?node=4359512471

How to reproduce the issue?

A live example: https://www.openstreetmap.org/edit?node=3645671154

Some tags have bidirectional text in values. The direction of the rendered text is determined by the first strong character in it: https://www.unicode.org/reports/tr9/#The_Paragraph_Level (P2)

In HTML this is achieved by adding dir="auto" to the element containing the text. This is why it's rendered correctly here: https://master.apis.dev.openstreetmap.org/node/4359512471

Image

But in iD they are all rendered in LTR - note especially the value of "he-en" and compare with above:

Image

If you change your OSM preferences to Hebrew or Arabic, they are all rendered RTL instead, which is also wrong:

Image

By adding dir="auto" to all input elements, the desired result is achieved (but may need some tweaking in CSS):

Image

This was achieved by inspecting the inputs and then running this in console: for (let x of document.getElementsByTagName("input")) {x.setAttribute("dir", "auto");} (just as a quick hack)

Screenshot(s) or anything else?

No response

Which deployed environments do you see the issue in?

No response

What version numbers does this issue effect?

No response

Which browsers are you seeing this problem on?

No response

NeatNit avatar May 30 '25 14:05 NeatNit

The fields in the Fields section should definitely respect the predominant writing direction via dir="auto". I’m less sure about the raw tag editor in the Tags section, since the point is to treat every value as code. Could initial or final punctuation cause additional confusion, especially if the user switches to text view, where every line is in the form k=v or k=*?

#9037 tracks more or less this same issue, but it seems to be focused on the raw tag editor, probably an oversight.

1ec5 avatar May 30 '25 18:05 1ec5

I’m less sure about the raw tag editor in the Tags section, since the point is to treat every value as code.

I'm not really sure what you mean here. Not every value is a code, and those that are will be in English or numeric anyway so would be rendered LTR by dir="auto". I think I'm missing something.

Could initial or final punctuation cause additional confusion, especially if the user switches to text view, where every line is in the form k=v or k=*?

Yeah, it could... but it can be confusing already as things stand today. There is no perfect solution for that.

I started writing this on my phone but expect another comment from me in a few minutes with screenshots from PC.

NeatNit avatar May 30 '25 20:05 NeatNit

Wait, I didn’t look closely enough – I thought the issue was just the alignment, but the runs of RTL and LTR are getting swapped too. That’s no good. Yes, I agree with setting dir="auto" on the raw tag editor in that case, at least for the tag view. Fortunately, the text view has enough text in it that it might not be influenced as much by the first tag’s value, hopefully.

1ec5 avatar May 30 '25 20:05 1ec5

So the thing is, k=v rendering is not something you should worry too much about. It's plaintext where the series of Unicode characters is all that matters. There is nothing to overthink there - how it gets rendered in text editors is just a natural consequence of the data. People who choose to edit this way are taking on that responsibility.

If a tag's key ends with RTL and its value starts with RTL, it can be rendered unintuitively:

https://master.apis.dev.openstreetmap.org/node/4359512471

Image

https://master.apis.dev.openstreetmap.org/edit?node=4359512471

Image

Image

There is nothing to be done about this. Fortunately, just about all keys on OpenStreetMap (or at least, the ones that matter) are English so this issue should never come about in practice.

But editing with a table is different - there the GUI separates keys from values in very clear ways. You mentioned values that end in punctuation - check this out:

Image

Image

... you just posted a comment so I don't think I need to convince you any more than this!

NeatNit avatar May 30 '25 20:05 NeatNit

Oh. Yeah, this does not seem optimal.

The text mode raw tag editor does appear to scramble the whole tag around in rtl mode, making it really hard to figure out what's going on:

~~I assume for this, the only reasonable thing to do is to force ltr direction for the full textarea, right?~~

//edit: ah, I see that setting "dir"="auto" works also for the textfield and does even handle the line with the rtl tag key reasonably well:

tyrasd avatar Jun 03 '25 13:06 tyrasd

You're right - for the tags textarea specifically dir="ltr" is good, maybe even preferable. As you noted, dir="auto" will ~always resolve to LTR anyway because of the way iD sorts the tags.

NeatNit avatar Jun 03 '25 15:06 NeatNit