-
Notifications
You must be signed in to change notification settings - Fork 22.5k
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
It seems to be unclear how to get an element's lang through inheritance #37680
Comments
Descendants inherit the behavior of the |
Thanks, JC.
In my use case I need to know the language of rach word in a text,
including those inside inner tags.
I can handle it with what I already did, but wanted to communicate the
uncertainty looming.
MDN is so good that it surprises me when something is not crystal clear.
Thanks for all!
Juan
…On Thu, Jan 16, 2025, 16:16 Joshua Chen ***@***.***> wrote:
Descendants inherit the *behavior* of the lang, such as with assistive
technologies or translation softwares. Descendants don't inherit the
*property*. You can't programmatically retrieve this property via
HTMLElement#lang, because that property simply reflects the HTML content
attribute, as specified. We should mention this on
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/lang, as we
already do for
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dir.
—
Reply to this email directly, view it on GitHub
<#37680 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHIBYOZ3CB6CD3WKIPPJOT2LAASXAVCNFSM6AAAAABVKFICR2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKOJWGYYDMMRZGQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Note there's a HTML spec issue about this problem, (whatwg/html#7039). The prefixed -webkit-locale CSS property has the lang that the browser will use for that element, only available in Chromium and WebKit based browsers. |
MDN URL
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang
What specific section or headline is this issue about?
Inheritance
What information was incorrect, unhelpful, or incomplete?
... or I didn't understand.
It reads: "If an element has no lang attribute, it will inherit the lang value set on its parent node, which in turn may inherit it from its parent, and so on."
It's not happening, at least the way I expect it to.
Descendants of an element with lang return a null lang property.
I understand that #text nodes have no lang, and this seems to cut the inheritance chain.
So I tried Element.closest('[lang]') and it also failed.
My nodes descend from a fragment, created from a page with lang at its . The fragment didn't come out with the page's lang, so I added it.
The descendants of the fragment don't seem to inherit its lang even after I brute-forced it.
StackOverflow has a number of developers wandering like zombies searching for the light.
I (one of those zombies) finally wrote a function to walk the hierarchy to do what I believed that closest() should do.
This is Chrome version 132.0.6834.83 (Official Build) (64-bit) in Ubuntu 22.04.5 LTS
What did you expect to see?
I expected the descendants elements of one having lang set, to proudly return their ancestor's lang.
Or, at least, closest to get it.
Do you have any supporting links, references, or citations?
No response
Do you have anything more you want to share?
Select text and press the button
Cannot upload html & js or 7z files :-(
MDN metadata
Page report details
en-us/web/html/global_attributes/lang
The text was updated successfully, but these errors were encountered: