openstreetmap / iD

🆔 The easy-to-use OpenStreetMap editor in JavaScript.
https://www.openstreetmap.org/edit?editor=id
ISC License
3.38k stars 1.21k forks source link

User language and LTR/RTL text-direction #4656

Open mapmeld opened 6 years ago

mapmeld commented 6 years ago

I was testing out the a RTL locale (dv) in Firefox on the OpenStreetMap site. In Firefox or Chrome, you can see the same results in Arabic (ar).

I think that I missed this earlier because I was testing the locale / browser-detection code, not knowing that the text language preference can be coming from OSM user preferences. Any idea where the locale text and direction are getting mixed up?

bhousel commented 6 years ago

Yeah the locale handoff from the OpenStreetMap Rails site to iD is tricky.. I think what is supposed to happen is

  1. Rails calls context.locale(), with your OSM language preference:

https://github.com/openstreetmap/iD/blob/b2eb982044c682656e101889d4b009eada8c0fbe/modules/core/context.js#L383-L388

  1. Rails calls id.ui()(container) to render iD into something:

https://github.com/openstreetmap/iD/blob/b2eb982044c682656e101889d4b009eada8c0fbe/modules/ui/init.js#L343-L355

  1. which calls context.loadLocale() to actually load the desired language file:

https://github.com/openstreetmap/iD/blob/b2eb982044c682656e101889d4b009eada8c0fbe/modules/core/context.js#L393-L398

  1. After it is loaded, the callback calls setLocale(), which sets the currentLocale variable. It's exported and used many places (kind of like a global variable):

https://github.com/openstreetmap/iD/blob/b2eb982044c682656e101889d4b009eada8c0fbe/modules/util/locale.js#L6-L12

  1. The callback also calls utilDetect(true) to redetect all the things.. It is supposed to use that currentLocale variable to override whatever iD detected from your browser. It's also supposed to lock in LTR or RTL:

https://github.com/openstreetmap/iD/blob/b2eb982044c682656e101889d4b009eada8c0fbe/modules/util/detect.js#L84-L100

  1. All those things should happen before the iD interface starts drawing itself into the container (see 2.). I'll have to test a bit, but I'm sure we can figure out where it is getting thrown off...
mapmeld commented 6 years ago

I wonder if setTextDirection should happen in setLocale then?