gantry / gantry5

:rocket: Next Generation Template / Theme Framework
http://gantry.org
1.03k stars 205 forks source link

Language declaration problem - Joomla 3 - latest version #3013

Open Schnok opened 2 years ago

Schnok commented 2 years ago

Hello,

I had a problem with the language declaration on a site in French (default language) and in English. On the front office the language declaration remained in French, , when switching to English.

In the concerned site there was a lot of duplication of template we did not define language for the basic templates (outline). I wondered if this could be the cause. I tried to correct this problem for the home page but it did not change anything. The declared language was always French.

Finally we modified the file libraries/gantry5/src/classes/Gantry/Framework/Page.php as below, and that fixed the problem.

In this file, I replace the code block:

public function htmlAttributes()
{
$attributes = [
lang' => $this->language,
dir' => $this->direction
]
+ (array) $this->config->get('page.html', []);

return $this->getAttributes($attributes);
}

With this one:
public function htmlAttributes()
{
/*$attributes = [
lang' => $this->language,
dir' => $this->direction
]
+ (array) $this->config->get('page.html', []);*/
$lang = Factory::getLanguage();

$attributes = [
lang' => $lang->getTag(),
dir' => $lang->isRtl() ? 'rtl' : 'ltr'
]
+ (array) $this->config->get('page.html', []);

return $this->getAttributes($attributes);
}

Best regards

mahagr commented 2 years ago

I just checked this and Gantry takes the language from the $document object. This is the correct way, but I have to check if the document passed to the template is different than the one used in this class.

mahagr commented 2 years ago

I just checked the code and it uses the document just like Joomla does. Also in my tests, the language is correct on pages of different languages.

To be honest, I don't know what's going on on your site and why it acts in a different way to my testing. One thing you can try is to check if the template has these three lines in the following files: https://github.com/gantry/gantry5/blob/develop/themes/helium/joomla/index.php#L24-L26 https://github.com/gantry/gantry5/blob/develop/themes/helium/joomla/component.php#L25-L27 https://github.com/gantry/gantry5/blob/develop/themes/helium/joomla/error.php#L25-L27 https://github.com/gantry/gantry5/blob/develop/themes/helium/joomla/offline.php#L24-L26

PS. I think you can just copy over the files.

Schnok commented 2 years ago

Hello Matias,

I have these 3 lines in these files. I'll take the time to do some more tests here and get back to you.

Best regards,