Is lang = unknown attribute valid?

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

I defined the lang attribute in the tag:

<html lang="en"> 

Some texts on the page are written in another language (for example, French):

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

But if I can’t identify the language, but I know that it is NOT English, can I set “unknown” as a valid value for the lang attribute?

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

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

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

lang = language code [CI] This attribute defines the base language of element attribute values ​​and text content. The default value for this attribute is unknown .

+4
source share
2 answers

The wording in the HTML 4.01 specification is unclear; unknown not a valid language tag, and the specification uses the word "unknown" as a normal English word. That is, the default value is a value indicating that the language is unknown, but this value is not explicitly specified.

The specification is partially outdated in this area because it relates to extruded RFCs on language tags. Current RFC RFC 5646 , Tags for identifying languages, also known as BCP (Best Modern Practice) 47. It relates, inter alia, to ISO 639-2 regarding primary language tags, and they contain the und code for "undefined". Technically, you can use lang=und , but the RFC says: "This subtag SHOULD NOT be used if a language tag is not required and language information is not available or cannot be determined. It is preferable to omit the language tag (where allowed)."

And this is the approach used in HTML5 RC, which says about lang : "Setting the attribute to an empty string means that the main language is unknown. [BCP47]"

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

This is, in principle, useful when you specify a language at a higher level of nesting. Setting lang="" may mean that user agents turn off language-specific spell-checking and formatting, for example, although this is still pretty theoretical.

+7
source

I would rather not install it at all if you don't need it. Note that the lang= value will be inferred from its closing (parent) element if it is not set.

If you are forced to install it in some way, setting it to unknown by default , as you already said, seems quite legal according to the specification.

0
source

Source: https://habr.com/ru/post/1469324/


All Articles