By iliphil on
I have a dual language d7 site with translated content - english and swedish with english being the default. It works mostly but what doesnt work is that the http content language header is always "EN" as well as the first html tag generated in system/html.tpl.php when I want it to match the node/content language.
I'm working around this with kludgy fix in my theme template.php but is there a better way?
function mytemplate_preprocess_html(&$variables) {
if(isset($variables['page']['content']['system_main']['nodes'])
&&
(sizeof($variables['page']['content']['system_main']['nodes'])==2 )
){
foreach($variables['page']['content']['system_main']['nodes'] as $k=>&$v){
if(gettype($v)=='array'){
if(isset($v['#node']->language) && ($v['#node']->language!='und')){
//echo $v['#node']->language;
$GLOBALS['language']->language=$v['#node']->language;
drupal_add_http_header('Content-Language', $v['#node']->language);
}
/*foreach($v['#node'] as $k =>$val) {
echo ', '.$k.'='. (is_string($val)?$val:gettype($val));
}*/
}
}
}
//print_r($variables['page']['system_main']);
}
Comments
By default, Drupal already
By default, Drupal already does this. So something in your system is overriding it. Rather than trying to override the override, you should try to track down where the problem is happening at its source. Start by trying a different theme, and if that doesn't fix it, then start disabling modules one by one until you find the module causing the issue.
Make sure to take a backup before you start so you can revert after you find the problem.
Contact me to contract me for D7 -> D10/11 migrations.
Or anything really. I'm friendly, and open to work or conversation.
Thanks for the answer but I can't see the override
It's not the theme - I have a bartik subtheme and I'm pretty sure none of the modules I have change the language values.
Drupal gets the values for language headers from the User interface language rather that from the content language. Sometimes these match but it depends on how the site is setup. I could be wrong about this but I have looked. My user interface language is set to default, no detection (english) for a few reasons, the main one being that I don't want to use the URL method and break a lot of links. But I still want the headers to match the content language rather that interface language that the language detection setting provides.
While trying to solve this I found a few more things that Drupal doesn't just do for multilingual content. When you have translations you want "rel = alternate" tages in the http headers and the page header for all the translations.
There is a module that does some of this in this module
https://www.drupal.org/project/i18n_contrib
I' haven't checked D8 to see what that does
Here is a final version of the template code I use that produces the right headers and the head tags for all the translation. It is a kludge..