Forum Moderators: open

Message Too Old, No Replies

indicating LANG to Search Engines

         

hafnius

11:24 pm on Nov 2, 2003 (gmt 0)

10+ Year Member



Hi all

I have a site in two languages. What is the best way of telling SE like Google which language the page is in, BTW im on XHTML 1.1, is it:

<body lang="x">

xml:lang="x"

Or both or maybe something different.

Kind Regards
Hafnius

encyclo

12:14 am on Nov 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In XHTML 1.1, you specify the language on the html tag using the xml:lang attribute, hence:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

The plain old lang attribute has been replaced in XHTML 1.1 by xml:lang, so if you use the former, it won't validate.

As for the search engines, I can't guarantee they'll recognise xml:lang, though - if it is important, you might want to consider using XHTML 1.0 Strict instead, where you can use this:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

Hope that helps!

BlobFisk

11:26 am on Nov 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you have mixed language content on a page, add the lang="" on the containing block, eg the <p> or the <div>. This not only tells the SE what language to expect next, but also people using assistive browsing technology (screen readers, braille displays etc.).

HTH

encyclo

1:11 pm on Nov 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you have mixed language content on a page, add the lang="" on the containing block

You're right about this, of course, but when you're using XHTML 1.1, the

lang
attribute will not validate. You can use:

<p xml:lang="fr">Ceci est en français</p>

But again, I'm not sure search engines (or adaptive technology like braille readers for that matter) will recognise xml:lang. You'd need to check it out before depending on it.

davidpbrown

1:30 pm on Nov 3, 2003 (gmt 0)

10+ Year Member



Where browsers don't accept the correct mime header xhml+xml I use the lang= and have had no problems.
Where it does I give the correct headers et al.
Strictly I suppose this shouldn't be done, but then I take that a UA doesn't understand the correct mime to suggest that they won't hold me to the strict 1.1, re. lang.

With php..
-----------
<?php
if (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")) { $x = "XML";
header("Content-Type: application/xhtml+xml; charset=utf-8");
echo '<?xml version="1.0" encoding="utf-8"?>';
echo "\n";
}
else { $x = "normal";
header("Content-Type: text/html; charset=utf-8");
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?php
if ($x == "XML") {echo "xml:";}
?>lang="fr">
<head>
----------

dpb

encyclo

1:58 pm on Nov 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nice code, david - personally, I would echo the
DOCTYPE
too, and then you could send an XHTML 1.1 doctype to user agents which accept
application/xhtml+xml
, and an XHTML 1.0 Strict doctype to the others - then your
lang
attribute would validate in both cases. (Actually, personally I'd use HTML 4.01 Strict, but that's another debate!)

encyclo

hafnius

9:56 pm on Nov 3, 2003 (gmt 0)

10+ Year Member



Thanx all

From what i can gather by the responses i will use only xml:lang="x" and hope the SE get which langugage the particular page is in.

Kind Regards
/Hafnius