Rectangle 27 75

As far as I can tell from reading the HTML5 spec the lang attribute:

value must be a valid BCP 47 language tag, or the empty string

There's no mention in the spec of an array of language strings and every example I've found uses a single language string.

This makes sense since really a given section can only be in one language unless we're creating a new hybrid language.

Since the lang attribute is valid on all HTML elements you can wrap your language specific code in a new tag in order to indicate its language.

<html lang="en">
[...]
<body>
<h1>I am a heading <span lang="de-DE">Eine berschrift</span></h1>
</body>
</html>

+1, wtf is a BCP 47 language tag? It it like the Posix locales (lang_ISOCC)?

BCP stands for "Best Current Practice" and the BCP 47 Track is where the Internet Engineering Task Force (IETF) outlines its IETF language tags. You can read more about it here en.wikipedia.org/wiki/IETF_language_tag

FYI - your w3.org link is broken. Tried briefly to find a replacement, but couldn't... Wish they followed their own advice and didn't break their URIs.

html5 - What attribute value should I use for a mixed l...

html html5 lang
Rectangle 27 339

How could I get the value of lang (where lang=eng in book title), for the first element?

/*/book[1]/title/@lang

Select the lang attribute of the title element that is a child of the first book child of the top element of the XML document.

To get just the string value of this attribute use the standard XPath function string()

string(/*/book[1]/title/@lang)

I used the string method and got the value in square brackets [attribute_value]. Is there a way to get the attribute value without the square brackets?

@AbhishekAsthana, The result of evaluating the XPath expression produces exactly the string value of the lang attribute. If the attribute doesn't contain any square brackets, they will not be part of the result of the evaluation of the XPath expression. My guess is that these are added by an (inappropriate) tool you are using.

yeah i figured out the problem..that's just how soapUI displays it but those brackets are not used when i use the xpath value. I have see this a lot of time. The problem is not with the tool..its between the chair and the keyboard.

@KorayTugay, the XPath expression /*/book[1]/title/@lang selects a node-set of 0 or more attribute nodes, while the XPath expression string(/*/book[1]/title/@lang) when evaluated, produces the string value of this node-set -- and this is the string value of the first (in document order) node from this node-set.

@KorayTugay, No, the first expression selects, doesn't "return" -- a set of nodes, and this set of nodes is not a string. A node is not a string -- a node is a node in a tree. An XML document is a tree of nodes. lang="eng" is just one of many textual representations of an attribute node that has a name "lang", doesn't belong to a namespace, and has a string value the string "eng"

xml - Getting attribute using XPath - Stack Overflow

xml xpath
Rectangle 27 28

Declaring language in HTML

Always use a language attribute on the html tag to declare the default language of the text in the page. When the page contains content in another language, add a language attribute to an element surrounding that content.

Use the lang attribute for pages served as HTML, and the xml:lang attribute for pages served as XML. For XHTML 1.x and HTML5 polyglot documents, use both together.

Use language tags from the IANA Language Subtag Registry.

also good read Why use the language attribute?

+1 for "Why use the language attribute" link. Much better than my explanation.

Bleh... the quoted content, which is simply an unexplained instruction to use the attribute, doesn't even remotely answer the question (which was WHY to use the attribute and what it does). This is effectively a link-only answer; the only content that's actually relevant to the question is at the 'Why use the language attribute?' link. I'll probably edit this later to shift the actually relevant content into the answer (or feel free to do so yourself).

What is lang attribute of the tag used for? - Stack Overflow

html
Rectangle 27 36

Everything I've seen and heard suggests that you should stick to

<!DOCTYPE html>
<html>
  <head>
    <meta charset='UTF-8'>

(or whatever character set you actually want). If you want a language associated with the page you can use the "lang" attribute on the <html> tag.

Since HTML5 is not XML, really, I personally would find it weird to use any xml: namespace stuff.

Cool, thanks. Then, I'll go with <html lang="en">, like LinkedIn does.

Oh, too bad that if you don't specify the xmlns attribute on html, it's not valid XHTML, and if you're aiming for polyglot markup that will render correctly when served as either HTML or XHTML, you need the xmlns attribute (because serving as application/xhtml+xml will otherwise display a document tree instead of a page). On the other hand, if you use the xmlns element in HTML5, the W3C validator will throw an error saying that the http-equiv in a <meta http-equiv="content-type"> is an invalid value, even though if you leave out the meta tag, it warns that you ought to add it to the document.

Also, even though HTML5 is not XML, it supports XHTML-like syntax on void elements like <br />, and it ends up putting everything in the XHTML namespace http://www.w3.org/1999/xhtml anyway.

@Triynko Is there an updated namespace that includes the tags: header, footer and the like?

XHTML5 is valid XML. And since there are uncounted XHTML parsers/processors that simply don't know what (X)HTML5 specifically is, it's not wise to omit xml:lang (and xmlns) in polyglot syntax.

HTML5 attributes xmlns, lang, xml:lang - Stack Overflow

xml html5 xml-namespaces
Rectangle 27 11

The lang attribute is not very well known but very useful. The attribute is used to identify the language of the content in either the whole document or in a single element. Langage codes are given in ISO 2-letter Language code (i.e. 'en' for English, 'fr' for French).

It's useful for browsers who can adjust their display of quotation marks, etc. Screen readers also benefit from the lang attribute as well as search engines.

lang

Specify the language to be English for the whole document, unless overridden by another lang attribute on a lower level in the DOM.

<html lang="en">

Specify the language in the following paragraph to be Swedish.

<p lang="sv">t din morgongrt och bli stor och stark!</p>

xhtml - Hidden features of HTML - Stack Overflow

html xhtml language-features hidden-features
Rectangle 27 2

Browsers that support <input type="number"> will always send a . as a decimal separator. You cannot change this, as this is per the HTML5 specifications for <input type="number">. The lang attribute is not relevant for the data that is sent to the server: the browser must always use a .. The lang attribute may be used for display purposes, however.

However, browsers that do not support <input type="number"> will send the number as you have typed it (with e.g., ,).

IMHO, this is highly problematic (and very anglocentric), since the server does not know whether the browser supports <input type="number"> or not, making parsing highly error prone (is "1.000" one thousand or one?).

The only way you can control what is sent, is by using <input type="text">. And if you want spinner functionality, you'll need to use custom JavaScript libraries, like jQuery UI.

<input type="text">
<input type="number">

Note that Internet Explorer will send number inputs as the user typed them, ignoring the specification.

I was looking to specification, but I found nothing about decimal separator, so can you send me link? Well, that's a reason to use lang attribut, with this attribute you can say what culture you're currently working. And reason why I want to use number is number keyboard on mobile devices - that field is for money amount, so this is pretty example to use number, I think.

@SebastianBusek, I've added a link to the HTML5 spec that comments on this.

c# - Number input replacing decimal comma with dot - Stack Overflow

c# asp.net-mvc html5 input number-formatting
Rectangle 27 3

If neither the node nor any of the node's ancestors, including the root element, have either attribute set, but 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.

So to summarise that, the lang of a node is determined by:

Note though that in text/html on the html element, xml:lang is not a lang attribute in the XML namespace, but a xml:lang attribute in no namespace, so its setting would not apply.

What is the default value - Stack Overflow

html lang
Rectangle 27 7

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.

I agree, if that's what the HTML 4.01 spec says then it's badly worded. If "unknown" is being used as an English word, then to me it says "We don't know what the default value is". I say there should be no statement of default value at all, as section 8.1.2 covers it, and so it's only "unknown" if there's no lang attribute on the element or any ancestor element, no Content-Language header, and no language set in the UA config.

html - Is lang=unknown attribute valid? - Stack Overflow

html lang
Rectangle 27 12

Depending of the language of the content - you often need to adapt the styling of an element.

One obvious example would be right-to-left languages.

Now say you want your website to support rtl languages - you would need:

<img src="myimage.gif" style="float:left" />

So now, if you want to support both languages, there's no way to assign a value to float using inline styling.

With CSS this is easily taken care of with the lang attribute

img {
  float:right;
}
html[lang="he"] img { /* Hebrew. or.. lang="ar" for Arabic etc */
  float:left;
}

inline styles - What's so bad about in-line CSS? - Stack Overflow

css inline-styles
Rectangle 27 12

Depending of the language of the content - you often need to adapt the styling of an element.

One obvious example would be right-to-left languages.

Now say you want your website to support rtl languages - you would need:

<img src="myimage.gif" style="float:left" />

So now, if you want to support both languages, there's no way to assign a value to float using inline styling.

With CSS this is easily taken care of with the lang attribute

img {
  float:right;
}
html[lang="he"] img { /* Hebrew. or.. lang="ar" for Arabic etc */
  float:left;
}

inline styles - What's so bad about in-line CSS? - Stack Overflow

css inline-styles
Rectangle 27 1

Here is a function that will return the value of the "lang" attribute of the nearest ancestor of any element, or undefined if none is found:

function elementLang(el) {
  while (el) {
    if (el.hasAttribute('lang')) {
      return el.getAttribute('lang');
    }
    el = el.parentElement;
  }
}

// From your example jsFiddle...
elementLang(document.getElementById('inner')); // => "es"
elementLang(document.getElementById('outer')); // => "es"
elementLang(document.getElementById('output')); // => undefined

This would be a better solution if you made it iterative instead of recursive. Recursion is generally slow and there's no need to use it here.

Simple iteration is generally certainly faster, you simply can't always use it to achieve what you want in a reasonable manner.

What about tail recursion on tail-call-optimizing interpreters or compilers?

See the second half of my comment.

html - How to determine an element's language with Javascript? - Stack...

javascript html
Rectangle 27 1

You could add a lang attribute to the HTML tag, like so: html lang="en" share|improve this answer answered Dec 9 '15 at 5:27 user2182349 6,27611429

I have already added this. But still the conversion of dot to comma happens.

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

javascript - Force chrome not to convert dot to comma in input type = ...

javascript angularjs html5 google-chrome
Rectangle 27 2

The OP specifically said "lang" not "language". The much older "language" tag would have been Javascript or VBScript.

But the current and seemingly valid "lang" tag is actually which written language like English, Spanish, Japanese. Microsoft's Visual Studio provides a dropdown list for the values for "lang" and they are all like en-us, fr, ja, etc.. for English US, French, Japanese, etc...

I'm thinking there could be valid reasons for using this tag if you have a complex multilingual setup - maybe there's a content mgmt system that could support this and then deliver the proper javascript file - like jQuery control resources?

That should be the correct answer. language and lang are different attributes.

html - What is the difference between "lang" and "type" attributes in ...

html scripting
Rectangle 27 27

The standard has been simplified because the previous doctypes were too cryptic. The new doctype is simply <!DOCTYPE html> . You may wonder why it is not <!DOCTYPE html5> but it is simply because it is just an update to the standard of HTML and not a new version of anything. As you can see below, all elements can now have a language attribute.

The <html> element is the root element of a document. Every document must begin with this element, and it must contain both the <head> and <body> elements.

It is considered good practice to specify the primary language of the document on this element using the lang attribute.

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Hello World</title>
    </head>
    <body>
        <h1>Hello World</h1>
        <p>
            Jamie was here.
        </p>
    </body>
</html>

html - What is the correct way to declare an HTML5 Doctype. - Stack Ov...

html html5 doctype
Rectangle 27 202

In case of a basic JSP/Servlet webapplication, the basic approach would be using JSTL fmt taglib in combination with resource bundles. Resource bundles contain key-value pairs where the key is a constant which is the same for all languages and the value differs per language. Resource bundles are usually properties files which are loaded by ResourceBundle API. This can however be customized so that you can load the key-value pairs from for example a database.

Here's an example how to internationalize the login form of your webapplication with properties file based resource bundles.

Create the following files and put them in some package, e.g. com.example.i18n (in case of Maven, put them in the package structure inside src/main/resources).

text.properties (contains key-value pairs in the default language, usually English)

text_nl.properties
nl
text_es.properties
es

The resource bundle filename should adhere the following pattern name_ll_CC.properties. The _ll part should be the lowercase ISO 693-1 language code. It is optional and only required whenever the _CC part is present. The _CC part should be the uppercase ISO 3166-1 Alpha-2 country code. It is optional and often only used to distinguish between country-specific language dialects, like American English (_en_US) and British English (_en_GB).

If not done yet, install JSTL. If you're running on a Servlet 2.5 container or newer (Tomcat 6.0 and so on) and your web.xml is declared conform the Servlet 2.5 specification, then just put jstl-1.2.jar in webapp's /WEB-INF/lib folder.

Create the following example JSP file and put it in web content folder.

login.jsp
<%@ page pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="language" value="${not empty param.language ? param.language : not empty language ? language : pageContext.request.locale}" scope="session" />
<fmt:setLocale value="${language}" />
<fmt:setBundle basename="com.example.i18n.text" />
<!DOCTYPE html>
<html lang="${language}">
    <head>
        <title>JSP/JSTL i18n demo</title>
    </head>
    <body>
        <form>
            <select id="language" name="language" onchange="submit()">
                <option value="en" ${language == 'en' ? 'selected' : ''}>English</option>
                <option value="nl" ${language == 'nl' ? 'selected' : ''}>Nederlands</option>
                <option value="es" ${language == 'es' ? 'selected' : ''}>Espaol</option>
            </select>
        </form>
        <form method="post">
            <label for="username"><fmt:message key="login.label.username" />:</label>
            <input type="text" id="username" name="username">
            <br>
            <label for="password"><fmt:message key="login.label.password" />:</label>
            <input type="password" id="password" name="password">
            <br>
            <fmt:message key="login.button.submit" var="buttonValue" />
            <input type="submit" name="submit" value="${buttonValue}">
        </form>
    </body>
</html>

The <c:set var="language"> manages the current language. If the language was supplied as request parameter (by language dropdown), then it will be set. Else if the language was already previously set in the session, then stick to it instead. Else use the user supplied locale in the request header.

The <fmt:setLocale> sets the locale for resource bundle. It's important that this line is before the <fmt:setBundle>.

The <fmt:setBundle> initializes the resource bundle by its base name (that is, the full qualified package name until with the sole name without the _ll_CC specifier).

The <fmt:message> retrieves the message value by the specified bundle key.

The <html lang="${language}"> informs the searchbots what language the page is in so that it won't be marked as duplicate content (thus, good for SEO).

The language dropdown will immediately submit by JavaScript when another language is chosen and the page will be refreshed with the newly chosen language.

You however need to keep in mind that properties files are by default read using ISO-8859-1 character encoding. You would need to escape them by unicode escapes. This can be done using the JDK-supplied native2ascii.exe tool. See also this article section for more detail.

A theoretical alternative would be to supply a bundle with a custom Control to load those files as UTF-8, but that's unfortunately not supported by the basic JSTL fmt taglib. You would need to manage it all yourself with help of a Filter. There are (MVC) frameworks which can handle this in a more transparent manner, like JSF, see also this article.

This nice solution has one issue: the locale taken from the request can be language and country, as in "en_US", which would give <html lang="en_US">, which is invalid HTML. It is necessary to use only the language part "en" from the locale as value for the lang attribute.

The method outlined above for internationalization does not amend the url based on the language displayed. Do you have any suggestions for how to update the url according to the language. I ask because, for indexing, it is recommended that different languages have separate urls: support.google.com/webmasters/answer/

If you put your language resource (test.properties and text_en.properties files) files at application/resources root, you can set the fmt:bundle like this: <fmt:setBundle basename="text" />

jsp - How to internationalize a Java web application? - Stack Overflow

java jsp unicode internationalization
Rectangle 27 2

<style type="text/css">
    // hides all French blocks by default
    div.story[lang="fr"] {
        display: none;
    }
    // hide all English blocks
    body[lang="fr"] div.story[lang="en"] {
        display: none;
    }
    // show all French blocks
    body[lang="fr"] div.story[lang="fr"] {
        display: block;
    }
</style>

<!-- Change this to the language of the blocks you want to display -->
<body lang="fr">

    <!-- English block, shown by default -->
    <div class="story" lang="en">
       <h1 class="title">Article Title</h1>
       <p class="content">Content of the Article.</p>
    </div>

    <!-- French block, hidden by default -->
    <div class="story" lang="fr">
       <h1 class="title">Titre de l'Article</h1>
       <p class="content">Contenu de l'Article.</p>
    </div>

</body>

This setup defaults to showing all English blocks, unless lang="fr" is set on the <body> tag.

Of course, you'll still need some way to modify the lang attribute of the <body> tag...

javascript - How to translate into other languages my web page? - Stac...

javascript html webpage translate
Rectangle 27 2

<style type="text/css">
    // hides all French blocks by default
    div.story[lang="fr"] {
        display: none;
    }
    // hide all English blocks
    body[lang="fr"] div.story[lang="en"] {
        display: none;
    }
    // show all French blocks
    body[lang="fr"] div.story[lang="fr"] {
        display: block;
    }
</style>

<!-- Change this to the language of the blocks you want to display -->
<body lang="fr">

    <!-- English block, shown by default -->
    <div class="story" lang="en">
       <h1 class="title">Article Title</h1>
       <p class="content">Content of the Article.</p>
    </div>

    <!-- French block, hidden by default -->
    <div class="story" lang="fr">
       <h1 class="title">Titre de l'Article</h1>
       <p class="content">Contenu de l'Article.</p>
    </div>

</body>

This setup defaults to showing all English blocks, unless lang="fr" is set on the <body> tag.

Of course, you'll still need some way to modify the lang attribute of the <body> tag...

javascript - How to translate into other languages my web page? - Stac...

javascript html webpage translate
Rectangle 27 3

Obviously, something needs to be escaped but I can't find any applicable examples. I am not a bash-wizard by any means

Whatever sort of wizard you are, you've sent the Stack Overflow dwarfs into Mirkwood. Your problem isn't the command escaping. The following will run fine.

find . -type f -print0 | xargs -0 sed -i '' 's/2013 Magento Inc./2012 Magento Inc./g'

Test this by running it in an empty directory.

$ mkdir tmp-gandalf
$ cd tmp-gandalf
$ find . -type f -print0 | xargs -0 sed -i '' 's/2013 Magento Inc./2012 Magento Inc./g'

If you had a shell escaping problem, your system would complain about it here.

Here's the problem. The first part of your command finds all the files to operate on

find . -type f -print0

Using -type f finds all the files. Including non-text files. The sed command doesn't like non-text files. Try something like this

sed -i '' 's/2013 Magento Inc./2012 Magento Inc./g' /path/to/some.gif
find . -name '*.php' -o -name '*.xml' -o -name '*.phtml'

Where /path/to/some.gif is a binary file. You'll see your sed: RE error: illegal byte sequence error. That's sed saying "wtf, I'm not as clumsy or random as a blaster. I come from a more civilized age where everything was ASCII".

This Stack Overflow question has a slightly hacky work around (jiggering the LANG attribute). I don't know enough to trust if this is a good idea or not.

My personal approach would be to limit your find such that only files with certain extensions are included. You can specify multiple name patterns with the -o option. So something like this

//NOTE: each -o needs its own -print0
find . -name '*.php' -print0 -o -name '*.xml' -print0 -o -name '*.phtml' -print0 | xargs -0 sed -i '' 's/2013 Magento Inc./2012 Magento Inc./g'

Would search .php, .xml, and .phtml files. You could add js files with another -o -name '*.js'. There should only be a handful of file types in the Magento code base with Copyright notices.

The binary file issue makes perfect sense, and thank you for using proper LOTR/SW phrasing so I would understand. Running your final command with multiple name params does execute, but the replacement isn't being written into the files. I understand that's what "sed -i" param is meant to do, but it doesn't seem to be having that effect. I also tried adding {} onto the end (I think this pipes the file list from the "find" command into "sed" but that had no effect. Any ideas?

I'm pretty sure you need to add -e so your command would look something like this find . -name "*.xml" -type f -exec sed -i -e 's/RegEx/Replacement/g' {} \;

bash - Replace string with spaces recursively using sed on Mac - Stack...

bash magento sed
Rectangle 27 6

In my opinion should the alt text always describe what is visible in the picture, for the case that the image is not displayed.

alt = text [CS] For user agents that cannot display images, forms, or applets, this attribute specifies alternate text. The language of the alternate text is specified by the lang attribute.

HTML img tag: title attribute vs. alt attribute? - Stack Overflow

html