Skip to content

Apply lang attribute to localized name:* values#6854

Open
Arpan200502 wants to merge 1 commit intoopenstreetmap:masterfrom
Arpan200502:add-lang-attribute-localized-tags
Open

Apply lang attribute to localized name:* values#6854
Arpan200502 wants to merge 1 commit intoopenstreetmap:masterfrom
Arpan200502:add-lang-attribute-localized-tags

Conversation

@Arpan200502
Copy link
Copy Markdown
Contributor

Description

Adds a lang attribute to localized tag values (e.g. name:fr, name:ja, alt_name:de) in the element Tags table.

The language code is extracted from the tag key and applied to the <td> element. This allows browsers to select appropriate fonts and improves accessibility for screen readers.

How has this been tested?

Tested locally by viewing elements with localized tags such as:

  • name:fr
  • name:ja
  • name:zh-Hans

Verified that the rendered <td> includes the correct lang attribute.

Closes #6834

@Arpan200502 Arpan200502 force-pushed the add-lang-attribute-localized-tags branch 3 times, most recently from 850562c to 1fa15dd Compare March 6, 2026 13:42
Comment thread app/views/browse/_tag.html.erb Outdated
Comment thread app/views/browse/_tag.html.erb Outdated
@Arpan200502 Arpan200502 force-pushed the add-lang-attribute-localized-tags branch 2 times, most recently from 108667f to 62cce1c Compare March 6, 2026 14:49
@Arpan200502 Arpan200502 requested a review from hlfan March 6, 2026 14:50
@Arpan200502
Copy link
Copy Markdown
Contributor Author

got it , i will try using helpers

@Arpan200502 Arpan200502 force-pushed the add-lang-attribute-localized-tags branch from 62cce1c to b6fe63c Compare March 6, 2026 15:56
@hlfan
Copy link
Copy Markdown
Collaborator

hlfan commented Mar 6, 2026

Could you add some tests that match the mentioned keys while excluding others?

@Arpan200502
Copy link
Copy Markdown
Contributor Author

Could you add some tests that match the mentioned keys while excluding others?

ok

@Arpan200502 Arpan200502 force-pushed the add-lang-attribute-localized-tags branch from b6fe63c to 223e280 Compare March 6, 2026 16:57
Comment thread test/helpers/browse_helper_test.rb Outdated
@Arpan200502 Arpan200502 force-pushed the add-lang-attribute-localized-tags branch from 223e280 to f13b509 Compare March 7, 2026 07:52
@Arpan200502 Arpan200502 requested a review from hlfan March 7, 2026 07:53
Comment thread app/views/browse/_tag.html.erb Outdated
<%= format_key(tag[0]) %>
</th>

<% lang = tag[0][/^name:([a-z]{2,3}(?:-[A-Z]{2})?)$/, 1] %>
Copy link
Copy Markdown
Collaborator

@1ec5 1ec5 Mar 8, 2026

Choose a reason for hiding this comment

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

This is good enough for most of the common keys, though it wouldn’t cover a few common ones like name:zh-Hant. We also have some variant name keys such as alt_name:fr that would benefit from the same treatment.

There are a few versions of a more comprehensive regular expression floating around (JavaScript and Java). The part of the regular expression after name: seems like something we might end up using for other purposes in the future, so maybe we could extract it into a constant or function somewhere.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since we only need to find the substrings most likely to be BCP-47 strings, not validate them, we can go for something a little bit simpler.

I've been trying out some variants; this is my current pick:
/.+:([a-zA-Z]{2,3}(?:(?:[^a-zA-Z:_'"]\w+)+|\b|$))/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok I will update that

Comment thread app/views/browse/_tag.html.erb Outdated
@Arpan200502 Arpan200502 force-pushed the add-lang-attribute-localized-tags branch from f13b509 to 485f513 Compare March 12, 2026 07:55
@Arpan200502 Arpan200502 requested review from 1ec5 and pablobm March 12, 2026 07:55
@Arpan200502 Arpan200502 force-pushed the add-lang-attribute-localized-tags branch from 485f513 to b31ad2d Compare March 12, 2026 08:06
@Arpan200502
Copy link
Copy Markdown
Contributor Author

Moved the language extraction logic out of the view into BrowseTagsHelper as suggested, and updated the view to call the helper instead of running the regex directly in the template.

Also switched to the broader regex discussed earlier to better detect language codes in tag keys. Existing tests rendering the partial continue to pass with the helper in place.

Copy link
Copy Markdown
Member

@tomhughes tomhughes left a comment

Choose a reason for hiding this comment

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

In addition to my inline suggestions can you fix the commit to not have a 180+ character first line?

To be honest I'd just go with something like:

Fix language detection for name:* tags in data browser

I'm not sure mentioning specific files in the commit comment is a good idea, and including tests for the change is something that's expected and doesn't really need to be mentioned explicitly but if you do want to add more detail then do it in a separate paragraph and keep the initial subject line short.

Comment thread app/views/browse/_tag.html.erb Outdated
Comment thread app/views/browse/_tag.html.erb Outdated
@Arpan200502 Arpan200502 force-pushed the add-lang-attribute-localized-tags branch 2 times, most recently from 879b8f0 to d66d766 Compare March 12, 2026 09:36
@Arpan200502 Arpan200502 requested a review from 1ec5 March 12, 2026 09:36
@Arpan200502
Copy link
Copy Markdown
Contributor Author

In addition to my inline suggestions can you fix the commit to not have a 180+ character first line?

To be honest I'd just go with something like:

Fix language detection for name:* tags in data browser

I'm not sure mentioning specific files in the commit comment is a good idea, and including tests for the change is something that's expected and doesn't really need to be mentioned explicitly but if you do want to add more detail then do it in a separate paragraph and keep the initial subject line short.

Thanks for the suggestions.

  • Updated the commit message to keep the first line within the 80-character limit.
  • Inlined tag_language(tag[0]) in the content_tag call and removed the temporary lang variable, since it was only used once.
  • Fixed the indentation accordingly.

@Arpan200502 Arpan200502 force-pushed the add-lang-attribute-localized-tags branch from d66d766 to d7437be Compare March 12, 2026 15:28
Comment thread app/views/browse/_tag.html.erb Outdated
Comment thread test/helpers/browse_helper_test.rb Outdated
Comment thread test/helpers/browse_helper_test.rb Outdated
@Arpan200502 Arpan200502 force-pushed the add-lang-attribute-localized-tags branch from d7437be to ca4451d Compare March 12, 2026 16:19
@Arpan200502 Arpan200502 requested a review from pablobm March 12, 2026 16:19
@Arpan200502 Arpan200502 force-pushed the add-lang-attribute-localized-tags branch from ca4451d to 2abba9a Compare March 13, 2026 13:02
Comment thread app/helpers/browse_helper.rb
Comment thread app/helpers/browse_helper.rb Outdated
Comment thread app/helpers/browse_helper.rb Outdated
@Arpan200502 Arpan200502 force-pushed the add-lang-attribute-localized-tags branch from 2abba9a to 9763d29 Compare March 15, 2026 05:40
@Arpan200502 Arpan200502 force-pushed the add-lang-attribute-localized-tags branch from 9763d29 to 25deeed Compare March 15, 2026 13:25
@tomhughes tomhughes changed the title Apply lang attribute to localized name:* values (#6834) Apply lang attribute to localized name:* values Mar 16, 2026
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes in this file are unrelated to the PR. Please remove them.

Comment thread app/helpers/browse_helper.rb
@tomhughes tomhughes added the ai-assisted Suggestions making extensive use of outsourced intelligence label Mar 31, 2026
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why not remove this partial entirely? Then some classes (py-1 border-secondary-subtle) can be reused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted Suggestions making extensive use of outsourced intelligence

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Apply lang to localized name:* values

5 participants