WordPress 2.1 introduces a new template function called language_attributes(). This function can be used to add lang, xml:lang and dir attributes to the html tag of your theme.
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
If your locale is currently set to “en”, the result looks like this:
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
If you are using a right-to-left language like Farsi, the output looks like this:
<html xmlns="http://www.w3.org/1999/xhtml" dir="rtl" lang="fa" xml:lang="fa">
To get the language and direction individually, use get_bloginfo().
$direction = get_bloginfo('text_direction');
$language = get_bloginfo('language');
language_attributes() is in 2.1 only, so adding it to your theme will make it incompatible with 2.0.x unless you take special precautions. Once 2.1 is out, this might be backported to 2.0.x.