Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve CJK names with a lang atttribute on multilingual name fields #10716

Merged
merged 6 commits into from
Jan 31, 2025

Conversation

mapmeld
Copy link
Contributor

@mapmeld mapmeld commented Jan 29, 2025

While researching issues with Chinese characters in OSM tiles and Mapnik, I realized that a similar issue exists in iD's multilingual name UI and it could be improved with a small change

Unicode CJK Unified Ideographs represents characters such as 化 with one codepoint. If the language of the element is Traditional Chinese (lang="zh-Hant"), the text renderer will display the same text differently (). Luckily we already have the language code when we are setting multilingual names name:zh=*, name:ja=, etc.

Screenshot 2025-01-29 at 12 51 35 AM

Possible issues:

  • I set the lang tag when loading the object. I didn't know how to make changing the language dropdown update the input's lang attribute without reorganizing the UI code and callbacks. Open to suggestions on how to do this in D3.
  • This doesn't change the appearance of the main name= tag since it can have any language(s)

@tyrasd tyrasd added the localization Adapting iD across languages, regions, and cultures label Jan 29, 2025
Copy link
Member

@tyrasd tyrasd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, setting the this is a good idea! It will likely also benefit screen reader output and other accessibility tools.

Regarding the implementation: yes, this should be set dynamically instead of when creating the dom element:

  • in d3, elements that have to be created are handled in <selection>.enter()
  • (similarly elements which need to be removed are handled in .exit())
  • all remaining elements are still in the original selection object
  • here, we have entries and entriesEnter
  • at some point these two are combined to get the full updated selection: entries = entries.merge(entriesEnter) (line 452)
  • you can use this object to set the properties of the existing and newly created dom elements
  • as the entries is the selection of the outer <div> elements, you need to select the correct <input> elements inside the divs first: entries.selectAll('input.localized-value')
  • using this sub-selection, you should be able to dynamically set the lang attribute

@tyrasd
Copy link
Member

tyrasd commented Jan 29, 2025

This doesn't change the appearance of the main name= tag since it can have any language(s)

Yeah, we could in theory try to guess the language of the name (e.g. by comparing name with any present name:* tags, or some heuristic based on characters in the name and/or the region of the mapped object). But it's also fine to leave this as is (for now).

@mapmeld
Copy link
Contributor Author

mapmeld commented Jan 29, 2025

I wasn't sure how to work with entries.selectAll('input.localized-value') but I did find that setting lang in another location, the utilGetSetValue callback, updates the lang attribute when the user changes the language.

mapmeld and others added 2 commits January 29, 2025 23:48
(i.e. wikidata descriptions and the respective wikipedia's native language name)

also some minor code readjusting
Copy link
Member

@tyrasd tyrasd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again!

Your implementation works because utilGetSetValue is also working on the input elements of the full set of entries (entries.selectAll('input.localized-value')). Sorry, my instructions must have been a bit confusing. 👍

FYI: In 239a373 I've added the remaining lang attributes on the input elements for wikidata descriptions and the wikipedia's native language name.

@tyrasd tyrasd merged commit 6dcc73c into openstreetmap:develop Jan 31, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
localization Adapting iD across languages, regions, and cultures
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants