inconsistency between no lang attribute (i.e. default language) and lang with an empty string
Categories
(Core :: Layout: Text and Fonts, defect)
Tracking
()
People
(Reporter: vincent-moz, Unassigned)
References
Details
Attachments
(1 file)
|
67 bytes,
text/html
|
Details |
When opening the following file
<!DOCTYPE html>
<html><body><p>m</p><p lang="">m</p></body></html>
the m characters do not appear in the same font. After testing:
- for the one without a
langattribute (i.e. default language value), the fonts for "Latin" are used; - for the one with
lang=""(empty string), the fonts for "Other Writing Systems" are used.
I do not see any reason for such a difference. This contradicts https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/lang ("The default value of lang is the empty string, which means that the language is unknown.").
Comment 1•9 months ago
|
||
The spec does give leeway in case no lang attribute is found. Namely:
If there is a pragma-set default language set, then that is the language of the node. If there is no pragma-set default language set, then language information from a higher-level protocol (such as HTTP), if any, must be used as the final fallback language instead. In the absence of any such language information, and in cases where the higher-level protocol reports multiple languages, the language of the node is unknown, and the corresponding language tag is the empty string.
| Reporter | ||
Comment 2•9 months ago
|
||
OK, but this is not clearly documented at https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/lang and nothing is said about how the absence of lang is handled by Firefox (and other Mozilla products) in particular. For instance, is the difference on the chosen fonts expected? If yes, where is this documented?
Note: I had opened the files locally (file: URL scheme).
Comment 3•9 months ago
|
||
Here's the reporter's testcase as a live attachment, for convenience.
Note:
(In reply to Vincent Lefevre from comment #0)
When opening the following file
<!DOCTYPE html> <html><body><p>m</p><p lang="">m</p></body></html>the m characters do not appear in the same font.
By default, the 'm' characters appear in the same font, for me at least -- here's what I needed to do to make them different (expanding on the "Latin"/"Other Writing Systems" note in comment 0):
- Visit
about:preferences - search for "Fonts"
- Click "Advanced"
- Choose "Latin" from the "Fonts for" drop-down, and ensure "Proportional" is set to "Serif" (the default)
- Choose "Other Writing Systems" from the "Fonts for" drop-down, and set "Proportional" to "Sans Serif" (non-default)
After doing this, then I do see that they end up in different fonts (we use Sans Serif for the second one).
Comment 4•9 months ago
|
||
Note that in bug 1727966 comment 6, jfkthame said:
Unrecognized lang values will end up using the "Other writing systems" setting
I imagine that's what's happening here -- we might be trying to match the empty string against a known lang value, and we don't find a match, and so it gets handled as part of the "Other writing systems" catch-all.
Comment 5•9 months ago
|
||
Following up on David's spec quote in comment 1 -- here's a bit of surrounding spec text that describes what's happening for the explicit lang="" scenario, I think (and matches our behavior):
If the node is an HTML element or an element in the SVG namespace, and it has a lang in no namespace attribute set
Use the value of that attribute.
[...]
If the resulting value is the empty string, then it must be interpreted as meaning that the language of the node is explicitly unknown.
https://html.spec.whatwg.org/multipage/dom.html#language
That seems to be what we're doing here -- we're using the attribute-value, which is the empty string, which means the language of the node is explicitly unknown, which means we hit the "Other writing systems" catch-all when deciding what language this node is in and what font to use for it.
Whereas in the case where there's no attribute, we take the "Otherwise" case in the spec's "if"-cascade there, with the text that David quoted in comment 1 (drawing on other sources of language information).
Comment 6•9 months ago
|
||
So I think Firefox's behavior matches the spec here, and the issue is just that the MDN quote in comment 0 is incorrect. I'll file an MDN issue on that to let the MDN editors know about that.
Updated•9 months ago
|
| Reporter | ||
Comment 7•9 months ago
|
||
(In reply to Daniel Holbert [:dholbert] from comment #5)
That seems to be what we're doing here -- we're using the attribute-value, which is the empty string, which means the language of the node is explicitly unknown, which means we hit the "Other writing systems" catch-all when deciding what language this node is in and what font to use for it.
But note that it is entirely Mozilla's choice to use different font settings for different kinds of languages. AFAIK, the spec does not mandate anything concerning the choice of the fonts. For instance, it would be perfectly valid to choose fonts based on which characters that appear in the document. However, this is a more general issue.
Comment 8•9 months ago
•
|
||
(In reply to Vincent Lefevre from comment #7)
But note that it is entirely Mozilla's choice to use different font settings for different kinds of languages. AFAIK, the spec does not mandate anything concerning the choice of the fonts. For instance, it would be perfectly valid to choose fonts based on which characters that appear in the document. However, this is a more general issue.
Our default font selections (on my system at least) are nearly all the same regardless of langauge -- "Latin" and "Other Writing Systems" have identical fonts selections, for example (which is why I had to manually change my font settings in comment 3 in order to see the issue that you were describing).
The only cases where I see them being different are that Arabic, Japanese, Korean, and Thai default to "Sans Serif" for their proportional font style - I believe because that those languages have a convention that interspersed Latin text will be shown in a sans-serif font. (I don't speak those languages or know the details, but I'm aware that there's some such cultural convention.) That's one example where basing the behavior on the declared language is necessary; you can't figure that out simply by checking for the presence of CJK characters in the document, because that wouldn't let you differentiate between a Japanese document with some Latin text (expected to be shown sans-serif) vs. an English document that happens to contain a long Japanese quote (perhaps even with more Japanese than English), which should default to serif despite the presence of the long Japanese quote.
| Reporter | ||
Comment 9•9 months ago
|
||
(In reply to Daniel Holbert [:dholbert] from comment #8)
Our default font selections (on my system at least) are nearly all the same regardless of language -- "Latin" and "Other Writing Systems" have identical fonts selections, for example (which is why I had to manually change my font settings in comment 3 in order to see the issue that you were describing).
One of the first things I do with a new profile is to change the default font settings: in particular, I change Proportional to "Sans Serif" (I find it better readable than "Serif" on screen, at least with small fonts) and the font size. And I usually do that only for the Latin script, as this is what I get for nearly all documents I read. That's why the settings for "Latin" and "Other Writing Systems" were different in my case.
[...] you can't figure that out simply by checking for the presence of CJK characters in the document, because that wouldn't let you differentiate between a Japanese document with some Latin text (expected to be shown sans-serif) vs. an English document that happens to contain a long Japanese quote (perhaps even with more Japanese than English), which should default to serif despite the presence of the long Japanese quote.
With the documents I have, the text has only Latin characters. So, in such a case, I would expect the Latin script when the language is unknown, and also when the script subtag in a lang attribute is absent, e.g. with romanized text in Asian languages, as the script subtag has never been mandatory (not even recommended): https://developer.mozilla.org/en-US/docs/Glossary/BCP_47_language_tag says that the script subtag is optional.
Description
•