Joomla module not picking up site language

35 views
Skip to first unread message

Jan Misker

unread,
Jun 11, 2018, 5:58:29 PM6/11/18
to Cookie Control Support
We have a Pro Multisite license, and want to offer multilingual consent screen. I configured the module to add a French version, and it indeed shows up correctly (according to the docs) in the config object.
However the site language seems to have no effect on this. Is the javascript perhaps only looking for the browser language, not the Joomla specified site language?

Aside from this: there was a bug in the helper.php file line 91+92. It puts alertColor in the settings object, but it should be alertText. 

Afroditi

unread,
Jun 12, 2018, 3:31:41 AM6/12/18
to Cookie Control Support
Hello Jan,
the plugin chooses the language based on user's browser settings and not the site's language.
Thank you for indicating the bug with the alertText color setting. It will be fixed in the next module release.
The module is published on Joomla extensions directory now, so the update process will be automatic.
Best Regards
Afroditi
Message has been deleted

Jan Misker

unread,
Jun 12, 2018, 9:45:16 AM6/12/18
to Cookie Control Support
For those interested, I made a little javascript to be included in the main template file. It checks the site language and updates the cookie consent screen. 
I include it right after the include for the cookie control module (I created a specific template position for it so I know for sure where it ends up).
$this->language is provided earlier in the template, based on JFactory::getDocument()->language

Could probably be nicer, but works for my scenario. The timer is needed because the CookieControl seems to load asynchronously and/or waits for dom (which makes sense of course).

Ideally there would be a setting in the Joomla module to honour site language besides browser language.

<jdoc:include type="modules" name="cookiecontrol" />
<script type="text/javascript">
var siteLang = '<?php echo $this->language; ?>';
if (window.config && config.locales && window.CookieControl) {
 
for (var i = 0; i < config.locales.length; ++i) {
 
if (siteLang.indexOf(config.locales[i].locale) == 0) {
 setTimeout
(function() {
 
CookieControl.update(this)
 
}.bind(config.locales[i]), 100);
 
}
 
}
}
</script>

Jan Misker

unread,
Jun 12, 2018, 12:41:46 PM6/12/18
to Cookie Control Support
Sorry, I thought that only the updated fields would be written, but the old and new config have to be merged.
I quickly made it like this:
if (siteLang.indexOf(config.locales[i].locale) == 0) {
var updatedConfig = config;
var locale = config.locales[i];
updatedConfig.text = locale.text;
updatedConfig.statement = locale.statement;
for (var j = updatedConfig.optionalCookies.length - 1; j >= 0; j--) {
updatedConfig.optionalCookies[j].label = locale.optionalCookies[j].label;
updatedConfig.optionalCookies[j].description = locale.optionalCookies[j].description;
}
setTimeout(function() {
CookieControl.update(this)
}.bind(updatedConfig), 100);
}



Reply all
Reply to author
Forward
0 new messages