I have a simple bilingual weblog with Drupal 7.19, i18n and a modified Bartik sub-theme.

Each page on weblog is available in two languages. I placed Language switcher (User interface text) Block on top of the site to allow visitors to switch to the other translation.

The problems is after a recent update of Drupal Core, validate.w3.org does not validate my weblog and complains that no attribute "lang" is allowed for a tag!

I tried to contact guys on IRC channel and they believe that I should issue this bug.

Comments

heine’s picture

Title: Language switcher (User interface text) Block generates invalid XHTML + RDFa! » Language switcher (User interface text) Block generates invalid XHTML+RDFa 1.0
Issue tags: -Bad html Formatting, -Bartik HTML5

A possible alternative to investigate would be a switch to XHTML+RDFa 1.1.

heine’s picture

Version: 7.19 » 7.x-dev
Status: Active » Needs review
StatusFileSize
new614 bytes
scor’s picture

Good catch. switching to XHTML+RDFa 1.1 would not really help since this is basically an XML parsing issue. #2 is the way to go. I could not find any other occurrence of lang (without the leading xml:) in core. Would be good to have @alimirjamali test the patch on http://blog.mirjamali.com/

GoddamnNoise’s picture

Issue summary: View changes

Hi. I've tested the patch and i've applied it in all my multilingual sites. It works!.

It would be nice if this patch could be committed to Drupal core to make Drupal 7 multilingual sites validate in the W3C validator.

GoddamnNoise’s picture

Any progress on this issue?. The patch is really simple, works nice and fixes a Drupal core's problem which prevents Drupal multilingual sites to validate in the W3C Validator. Please, could any Drupal core's commiter review this issue and commit this useful patch to Drupal core?.

heine’s picture

If you've reviewed and tested the patch sufficiently, please set the status of this issue to "Reviewed & tested by the community" to get it into the committer queue.

GoddamnNoise’s picture

Status: Needs review » Reviewed & tested by the community
GoddamnNoise’s picture

Ok, done!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 2: 1904528-lang-attr.patch, failed testing.

Status: Needs work » Needs review

dcam queued 2: 1904528-lang-attr.patch for re-testing.

dcam’s picture

Status: Needs review » Reviewed & tested by the community
David_Rothstein’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +7.36 release notes

This looks right to me; I guess what happened here is that when the original change was backported from Drupal 8 the difference in HTML vs XHTML wasn't taken into account.

Committed to 7.x - thanks!

  • David_Rothstein committed 26d794f on 7.x
    Issue #1904528 by Heine, GoddamnNoise: Language switcher (User interface...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

dalin’s picture

Status: Closed (fixed) » Needs review
StatusFileSize
new527 bytes

Wondering if we need to revert this commit. It seems to me that this commit just swapped XHTML errors for HTML errors. When using an HTML5 doctype the W3C HTML validator throws an error:

Error: When the attribute xml:lang in no namespace is specified, the element must also have the attribute lang present with the same value.

Doesn't Drupal 7 support both doctypes? Shouldn't we be supplying both attributes?

$result[$langcode]['attributes']['lang'] = $langcode;
$result[$langcode]['attributes']['xml:lang'] = $langcode;		
dalin’s picture

Ah yes, we should be supplying both:
http://www.w3.org/TR/xhtml1/#C_7

geekygnr’s picture

Status: Needs review » Reviewed & tested by the community

#15 solved my validation issue using 7.43

das-peter’s picture

From what I could figure out providing both indeed seems the best way.

stefan.r’s picture

Issue tags: +Pending Drupal 7 commit

Looks good to me, marking for Drupal 7 commit.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Pending Drupal 7 commit

I tried this on http://validator.w3.org/ (with the language switcher block enabled on my local site) and it reintroduces the original bug that was fixed here - the validation error is there is no attribute "lang".

I'm not sure what to do about it - core uses XHTML+RDFa 1.0 by default so if we have to pick one to work with, it should be that (i.e. the original patch that was committed here is correct as is).

It's a real pain to ask HTML5 themes that want to validate to deal with this on their own, but I do think it's possible via https://api.drupal.org/api/drupal/modules%21system%21language.api.php/fu.... Only way I can think of to improve that would be if there is some way we can detect (or let a theme declare) what kind of doctype they are going to use, but the fix might turn out to be more complicated than the workaround.

GoddamnNoise’s picture

I've faced the same problem reported in #15 too. The patch in #15 solves fixes the HTML Validation. I couldn't check if the original bug was reintroduced because of the html tag used in the theme.

edurenye’s picture

Status: Needs work » Reviewed & tested by the community

I'm not sure if was a error on validator.w3.org what was reported in #20, but seems fixed now. The patch in #15 fixes the errors and does not add any extra error.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Needs review

@edurenye What theme are you using for your tests? My guess is an HTML5 theme, in which case the problem would not occur there.

#20 was done using Bartik. I just tried it again now and got the same validation error I got before.

edurenye’s picture

Status: Needs review » Needs work

Yes, you are right, I tested it with the Zen theme. But there it fixes the error, previous to the patch I had the error, so it also occurs there.

We need a solution that works for both cases.

If it does not fix the error, then is a needs work, not a needs review.

joseph.olstad’s picture

patch 15 fixed the w3c validation error for us using a custom html5 theme.

I used the w3.org validator, before patch, language-link fails validation, after patch, clean.

I did not test Bartik though. Will take David_Rothsteins word for it.

I'd say html5 is the norm now, so maybe change the default theme in D7 core from bartik to bootstrap. (add bootstrap 7.x-3.x to core)
this could be done in the 7.60 or 7.70 new feature releases.

othermachines’s picture

I came across the validation error on a search results page. For consistency it might make sense to also include both attributes in the core preprocess function as below (see comment).

/**
 * Process variables for search-result.tpl.php.
 *
 * The $variables array contains the following arguments:
 * - $result
 * - $module
 *
 * @see search-result.tpl.php
 */
function template_preprocess_search_result(&$variables) {
  global $language;

  $result = $variables['result'];
  $variables['url'] = check_url($result['link']);
  $variables['title'] = check_plain($result['title']);
  if (isset($result['language']) && $result['language'] != $language->language && $result['language'] != LANGUAGE_NONE) {
    $variables['title_attributes_array']['xml:lang'] = $result['language'];
    $variables['content_attributes_array']['xml:lang'] = $result['language'];
    
    // Also add 'lang' attribute.
    $variables['title_attributes_array']['lang'] = $result['language'];
    $variables['content_attributes_array']['lang'] = $result['language'];
  }
  //
  // snipped ...
  //
}

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.