Is lang=unknown attribute valid?

落花浮王杯 提交于 2019-12-23 11:45:42

问题


Given an HTML document in a specific language (english).

I have defined a lang attribute on the tag :

<html lang="en">

Some texts in the page are written in another language (for example french) :

<span lang="fr">
  blabla...
</span>

But, if I can not identify the language, but I know it is NOT english, can I set "unknown" as a valid value for lang attribute?

<span lang="unknown">
  blabla...
</span>

I read this in w3c documentation, but I am not sure if "the default value is [...] unknown" means that "unknown" is a real value...

http://www.w3.org/TR/html4/struct/dirlang.html

lang = language-code [CI] This attribute specifies the base language of an element's attribute values and text content. The default value of this attribute is unknown.


回答1:


The wording in the HTML 4.01 specification is obscure; the value unknown is not a valid language tag, and the spec uses the word “unknown” as a normal English word. That is, the default value is a value that indicates that the language is not known, but this value is not explicitly specified.

The spec is partly outdated in this area, as it refers to a superseded RFC on language tags. The current RFC is RFC 5646, Tags for Identifying Languages, also known as BCP (Best Current Practice) 47. It refers, among other things, to ISO 639-2 as regards to primary language tags, and they contain the code und for “undetermined”. So technically you could use lang=und, but the RFC says: “This subtag SHOULD NOT be used unless a language tag is required and language information is not available or cannot be determined. Omitting the language tag (where permitted) is preferred.”

And this is the approach adopted in HTML5 RC, which says about lang: “Setting the attribute to the empty string indicates that the primary language is unknown. [BCP47]”

Thus, for text in unidentifiable language you can use e.g. <span lang="">...</span>.

This is, in principle, useful when you have indicated the language at a higher level of element nesting. Setting lang="" may mean that user agents disable spelling checks and language-specific formatting, for example, though this is still rather theoretical.




回答2:


I would prefer not setting it at all if you don't have to. Note that the lang= value will be derived from its enclosing (parent) element if it is not set.

If you are somehow forced to set it, setting it to the default unknown as you already suggested seems perfectly legit according to the specification.



来源:https://stackoverflow.com/questions/15416683/is-lang-unknown-attribute-valid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!