Bug 286290

Summary: Add support for the lang attribute in SVG
Product: WebKit Reporter: Deleted User <deleted_user>
Component: SVGAssignee: Karl Dubost <karlcow>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, fantasai.bugs, karlcow, sabouhallawa, vitor.roriz, webkit-bug-importer, zimmermann
Priority: P2 Keywords: InRadar
Version: Other   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=286420
Attachments:
Description Flags
rendering in safari, firefox, chrome none

Attachments
rendering in safari, firefox, chrome (149.65 KB, image/png)
2026-04-02 07:46 PDT, Karl Dubost
no flags
Radar WebKit Bug Importer
Comment 1 2025-01-28 03:45:14 PST
Karl Dubost
Comment 2 2026-04-02 07:46:15 PDT
Created attachment 478905 [details] rendering in safari, firefox, chrome The test is failing just because of the font chosen to render the text I guess. Maybe Vitor knows why?
Karl Dubost
Comment 3 2026-04-02 08:11:26 PDT
Code snippet for the console to extract the relevant information for each browser: document.querySelectorAll('text, tspan').forEach(el => { console.log( el.tagName + ' lang=' + el.getAttribute('lang') + ' matches:lang(ja)=' + el.matches(':lang(ja)') + ' matches:lang(zh-CN)=' + el.matches(':lang(zh-CN)') + ' matches:lang(zh-TW)=' + el.matches(':lang(zh-TW)') + ' "' + el.textContent.trim().substring(0, 20) + '"' ); }); Safari: [Log] text lang=null matches:lang(ja)=false matches:lang(zh-CN)=false matches:lang(zh-TW)=false "今骨直 今骨直 今骨直" [Log] tspan lang=ja matches:lang(ja)=true matches:lang(zh-CN)=false matches:lang(zh-TW)=false "今骨直" [Log] tspan lang=zh-CN matches:lang(ja)=false matches:lang(zh-CN)=true matches:lang(zh-TW)=false "今骨直" [Log] tspan lang=zh-TW matches:lang(ja)=false matches:lang(zh-CN)=false matches:lang(zh-TW)=true "今骨直" Firefox: text lang=null matches:lang(ja)=false matches:lang(zh-CN)=false matches:lang(zh-TW)=false "今骨直 今骨直 今骨直" debugger eval code:2:13 tspan lang=ja matches:lang(ja)=true matches:lang(zh-CN)=false matches:lang(zh-TW)=false "今骨直" debugger eval code:2:13 tspan lang=zh-CN matches:lang(ja)=false matches:lang(zh-CN)=true matches:lang(zh-TW)=false "今骨直" debugger eval code:2:13 tspan lang=zh-TW matches:lang(ja)=false matches:lang(zh-CN)=false matches:lang(zh-TW)=true "今骨直" Chrome: text lang=null matches:lang(ja)=false matches:lang(zh-CN)=false matches:lang(zh-TW)=false "今骨直 今骨直 今骨直" VM17:2 tspan lang=ja matches:lang(ja)=true matches:lang(zh-CN)=false matches:lang(zh-TW)=false "今骨直" VM17:2 tspan lang=zh-CN matches:lang(ja)=false matches:lang(zh-CN)=true matches:lang(zh-TW)=false "今骨直" VM17:2 tspan lang=zh-TW matches:lang(ja)=false matches:lang(zh-CN)=false matches:lang(zh-TW)=true "今骨直"
Karl Dubost
Comment 4 2026-04-02 08:14:51 PDT
HTMLElement::collectPresentationalHintsForAttribute() (HTMLElement.cpp:259-265) maps lang and xml:lang to -webkit-locale via mapLanguageAttributeToLocale(), which calls addPropertyToPresentationalHintStyle(style, CSSPropertyWebkitLocale, ...). SVGElement::collectPresentationalHintsForAttribute() (SVGElement.cpp:1026-1031) only handles SVG-specific presentation attributes (fill, stroke, etc.) via cssPropertyIdForSVGAttributeName(). It does not handle lang/xml:lang at all. The language never becomes a -webkit-locale presentational hint.
Karl Dubost
Comment 5 2026-04-02 08:17:01 PDT
Add lang/xml:lang → -webkit-locale mapping in SVGElement, mirroring what HTMLElement does. SVGElement.cpp — hasPresentationalHintsForAttribute(): ============ bool SVGElement::hasPresentationalHintsForAttribute(const QualifiedName& name) const { if (cssPropertyIdForSVGAttributeName(name, document().settings()) > 0) return true; if (name.matches(XMLNames::langAttr) || name.matches(HTMLNames::langAttr)) return true; return StyledElement::hasPresentationalHintsForAttribute(name); } ============ SVGElement.cpp — collectPresentationalHintsForAttribute(): ============ void SVGElement::collectPresentationalHintsForAttribute(const QualifiedName& name, const AtomString& value, MutableStyleProperties& style) { CSSPropertyID propertyID = cssPropertyIdForSVGAttributeName(name, document().settings()); if (propertyID > 0) addPropertyToPresentationalHintStyle(style, propertyID, value); else if (name.matches(XMLNames::langAttr)) mapLanguageAttributeToLocale(value, style); else if (name.matches(HTMLNames::langAttr) && !hasAttributeWithoutSynchronization(XMLNames::langAttr)) mapLanguageAttributeToLocale(value, style); } ============ Note: mapLanguageAttributeToLocale() is currently a private method on HTMLElement.
Karl Dubost
Comment 6 2026-04-02 09:22:15 PDT
EWS
Comment 7 2026-04-02 20:41:27 PDT
Committed 310495@main (f7fa439ccd03): <https://commits.webkit.org/310495@main> Reviewed commits have been landed. Closing PR #61919 and removing active labels.
Note You need to log in before you can comment on or make changes to this bug.