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.
Nice. For those of us using a blog that is in a language that reads right to left, I could see this being very useful.
Also very useful in a way of bringing WordPress even further beyond the rest of the blogging systems out there.
Great edition Ryan,
Any suggestions on how to differentiate between 2.1 and 2.0.x in order to ensure the theme works for both versions?
I probably wont personally use it, but it’s a great leap forward in terms of accessibility that the team should be proud of. It might encourage some bloggers in other languages to use wordpress, too.
I do agree with Matt. this will put WordPress far beyond not only the current blogging systems but also all the web applications which simply ignored right to left languages and localization in general.
Localization is not simply translating the phrases and I am really delighted to see wordpress is proving it in action. Thanks to Ryan, Matt and Mani.
this is NOT “Farsi language”, this is “Persian language” 😉
I’m glad you’ve finally taken steps to help RTL language bloggers.
The Hebrew WordPress community is still growing slowly with our own adaptions.
I would however, like to try this version and the new RTL features. I’m not sure how much impact this has, because directionality is not enough; themes need to be carefully fitted to RTL, with additions such as {text-align:right;) etc.
What else does this affect?
Also, I think a better thing to do, would be to set that if the directionality is RTL, WordPress should load “stylertl.css” instead the normal packages. That’s in case you would like to display the RTL abilities with English, international WordPress installation out of the box.
I hope you’re catching my drift.
I’ve seen it working wonderfully on LifeType and I’m sure it can be done on WP.
Ryan, are those
get_bloginfo()
arguments new ones for 2.1? I’m just wondering what I can do to improve the situation for blogs running (and still running, once 2.1 comes out) 2.0.x that improves on just leaving my theme withxml:lang="en" lang="en"
in as the default.Ajay use:
if ( function_exists(‘language_attributes’) ) { language_attributes(); }