HTML Primary Language Tag with Language Switcher

109 views
Skip to first unread message

Brad Gies

unread,
Jun 13, 2013, 7:14:59 PM6/13/13
to joomla-...@googlegroups.com

I've been noticing in my multi-language sites that there is no Meta Tag specifying the language of the page, which seems to be an oversight.

The best W3 document I've found is this one: http://www.w3.org/International/tutorials/new-language-decl/qa-http-and-lang

And the recommendation is to use this: <html lang="en">

My Questions are: Is there a way in Joomla right now to add the Content-Language tag? If not, is anyone interested in having it added? If so, what is your opinion on how best to add it, and where should the option be to add it to the page or not add it?

From my looking around, it seems the logical place to put the option would be on the System-Language Filter plugin, as that seems to be where all the other options are.

Appreciate any input. Thanks.

-- 
Sincerely,

Brad Gies
----------------------------------------------
bgies.com              maxhomevalue.com 
idailythought.com      greenfarminvest.com
---------------------------------------------- 

brian teeman

unread,
Jun 13, 2013, 7:43:34 PM6/13/13
to joomla-...@googlegroups.com
Is this in joomla 3 or 2.5

brian teeman

unread,
Jun 13, 2013, 7:55:04 PM6/13/13
to joomla-...@googlegroups.com
I ask because in joomla 3 there is a core plugin System - Language Code that does exactly what you want
eg
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr-fr" lang="fr-fr" dir="ltr">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" dir="ltr">

Brad Gies

unread,
Jun 13, 2013, 9:40:15 PM6/13/13
to joomla-...@googlegroups.com

Sorry... incomplete info... J 2.5, but I didn't know it was there for 3 either, and I do have a J3 multi language site, so I'll take a look at that one. Thanks.
--
You received this message because you are subscribed to the Google Groups "Joomla! CMS Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-cm...@googlegroups.com.
To post to this group, send an email to joomla-...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-cms.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Matt Thomas

unread,
Jun 13, 2013, 9:53:26 PM6/13/13
to joomla-...@googlegroups.com

Typically, I've seen this coded directly in the site template, i.e. https://github.com/construct-framework/bootstruct/blob/master/index.php#L28

Best,

Matt Thomas
Founder betweenbrain™
Lead Developer Construct Template Development Framework
Phone: 203.632.9322
Twitter: @betweenbrain
Github: https://github.com/betweenbrain

Composed and delivered courtesy of Nexus 7.

JM Simonet

unread,
Jun 14, 2013, 7:07:26 AM6/14/13
to joomla-...@googlegroups.com
Core templates do include the necessary code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>" >

I suggest you add this to the index.php of your template.

JM
--

You received this message because you are subscribed to the Google Groups "Joomla! CMS Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-cm...@googlegroups.com.
To post to this group, send an email to joomla-...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-cms.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


-- 
Please keep the Subject wording in your answers
This e-mail and any attachments may be confidential. You must not disclose or use the information contained in this e-mail if you are not the
intended recipient. If you have received this e-mail in error, please notify us immediately and delete the e-mail and all copies.
-----------------------------------------------------------
Jean-Marie Simonet  /  infograf768
Joomla Production Working group
Joomla! Translation Coordination Team 

Brad Gies

unread,
Jun 14, 2013, 12:11:20 PM6/14/13
to joomla-...@googlegroups.com

Ok... I do see the code in the core templates, but it is missing in the templates I use :(.

I also checked my J 3.1 site, and the Language code plugin is enabled, but the language attribute doesn't get rendered. I just made a backup, and will debug it this morning, and let you know if I find something Joomla! can fix. I'd assume it is also a template issue though.

Thanks Brian, Michael and JM. Much appreciated.

Brad.

Brad Gies

unread,
Jun 14, 2013, 2:52:10 PM6/14/13
to joomla-...@googlegroups.com

After a little debugging, it became clear that my template only included <html>, and the Language Code plugin in J 3.1 only replaces the language code if the language code already exists. I did find where to include the language attribute in my template (not quite as easy as I expected however, because the template uses a framework), and making that change to the template does allow the Language code plugin to work as expected, and it does replace the code as I want.

However, it seems to me that if the template only includes <html> that the Language Code plugin should go ahead and add the Lang and dir attributes to the HTML tag. Do you agree? Looking at the code in languagecode.php, I'm not sure what the best way of doing it would be but it seems to me adding something like:

preg_replace('<html>', '<html lang="<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>" $body);

at about line 58 (before the calls to preg_match_all) would do it. You probably can't add the XML attributes because the template might be defining something else as the docType (HTML 5).

NOTE that I haven't given this a lot of thought, and I'm confident other people know a lot more about this than I do, so I will defer to their wisdom ;).

I still have the J2.5 issue, and I haven't looked at it yet, but hopefully I can find a way to make that work.

Thanks for the help,


Brad.






On 14/06/2013 4:07 AM, JM Simonet wrote:

Matt Thomas

unread,
Jun 14, 2013, 3:05:29 PM6/14/13
to joomla-...@googlegroups.com
I've run into a similar situation with a plugin prototype that manipulates the class attribute of the body tag. At https://github.com/betweenbrain/Dynamic-Body-Class-Plugin/blob/develop/dynamic_body_class.php#L31 you can see how I handled it if there was no class attribute, much like you ran into with the lang not being present. There might be a better way to do, but that seems to work.

Best,

Matt Thomas
Founder betweenbrain
Phone: 203.632.9322
Twitter: @betweenbrain



elin

unread,
Jun 20, 2013, 1:02:46 AM6/20/13
to joomla-...@googlegroups.com
I'm wondering why we are not  doing language as part of creating the  rest of the metadata rather than relying on templaters.  

Elin
Reply all
Reply to author
Forward
0 new messages