phetsims / chipper

Tools for developing and building PhET interactive simulations.
MIT License
11 stars 14 forks source link

Adjust HTML language attribute #1332

Open jonathanolson opened 2 years ago

jonathanolson commented 2 years ago

We should be setting the lang attribute on the HTML element. Should assess whether this is maintenance-release-worthy. We won't mess with the lang attribute on the PDOM.

Notes from dev meeting:

✓JB: A question came up during today’s status meeting about whether we support the HTML “language attribute”.  I don’t know much about this, and none of the other devs seemed to either.  Should we do some investigation about supporting this?
JG: We have `lang=”en”` set on the root element of the PDOM.
MV: Looking at the published simulations on the website, there is no lang attribute in the html and meta tags. 
JB: Does lang attribute exactly match with our ISO codes?
LM: No, in attribute it's en-US whereas in code it's en_US, but maybe roughly the same?
SR: It sounds easy to change the lang attribute dynamically when locale changes, but what context should this be tested in?  How will we know if it is appearing correctly for clients.  What dom element should get the lang attribute?
KP: Will this impact how the browser offers to translate the page?
SR: Should we choose a subteam to investigate, and at what priority?
KP: JO can you please make an issue and take the lead on this?
JB: I’m happy to help as well.
KP: Can you also assess if this is a maintenance-releasable change
JG: The PDOM handles this correctly, lets not change that pleas
jbphet commented 3 months ago

@jonathanolson - This is assigned to me, and has been for over a year, but I don't know what I should do about it. Is it assigned to me because I generally take care of Rosetta (the sim translation utility)? If so, how should Rosetta change to support this?

I'm going to unassign myself for now. Feel free to assign this back to me when there is a bit more information about it, or to set up a meeting to discuss.

pixelzoom commented 13 hours ago

Doing a search for "Can html lang attribute change after page is loaded", I find this article that suggests changing lang after the page is loaded could be problematic for screen readers: https://stackoverflow.com/questions/41592689/does-changing-the-html-lang-attribute-after-page-load-have-any-effect

So the general question is… Are there things that read the lang attribute when the page is loaded, and that will not know that lang is changed? And will that cause problems?

jessegreenberg commented 8 hours ago

Additional notes taken during dev meeting:

SR: Ideally, this would change dynamically based on query parameter + preferences dialog. Does our standard (for what locale codes we use) match the browser standard for locale codes?
According to [this MDN page](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang), lang uses “BCP47” ([this](https://datatracker.ietf.org/doc/html/rfc5646) says that is equivalent to ISO 639)
JB: Is that valid in HTML5 - to change the lang attribute of the document based on the query parameter?
JG: gpt-4o says its common to change it, if we trust that
JG: It’s fine for it to change - can we change this in main and skip the MR?
The dev team thinks this is fine
MK: Let’s add an issue to joist and implement this - changing the locale will update the lang attribute on the html document
CM: Could this affect screen readers?
TS: Screen readers will be on the PDOM, so as long as that is updated we should be ok
CM: So the question is… Are there things that read the lang attribute when the page is loaded, and that will not know that lang is changed. And will that cause problems?
https://github.com/phetsims/chipper/issues/1332#issuecomment-2377637143 
SR: https://stackoverflow.com/questions/28459846/when-changing-languages-dynamically-should-the-html-lang-attribute-be-updated
https://stackoverflow.com/questions/35187645/how-to-set-html-lang-attribute-dynamically
TS will make an issue about this in joist, and the sub-team will handle it from here (we have an issue)
Other links:
Adjust HTML language attribute · Issue #1332 · phetsims/chipper (github.com)
SR: Map from our locale codes to the correct standard
See https://github.com/phetsims/chipper/issues/1332 
TS: Since the lang attribute can be added anywhere in a page, I have a feeling a dynamic lang attribute is not a problem, but not having a lang attribute is a known problem. We can verify a dynamic language attribute is generally safe and a good practice.