Droplet: Language Switcher URL

lash

#1
Hi... i build a little droplet based on the Language Switcher Snippet. The code is much shorter but it uses the same technique. So the requirements are the same. The menu trees of the different languages have to be the same. If there's no corresponding page use a dummy page (with visibility set to hidden or none). In this case the language root is returned.
You also have to set the language attribute of all pages correctly. Normally you only have to do this for the root entries (EN, DE, ...), on all other pages it is automatically set to its parent value.

The droplet only returns the URL, so you have to build the links yourself!


<?php

global $database$wb;

$url WB_URL.$_SERVER['PHP_SELF'];

if (
strtolower(LANGUAGE) != strtolower($lang)) {

// get additional page info
$sql "SELECT position, menu FROM ".TABLE_PREFIX."pages WHERE page_id = ".PAGE_ID;
$get_content $database->query($sql);
$page_info $get_content->fetchRow();

// get link
$sql = "SELECT link, visibility FROM ".TABLE_PREFIX."pages ";
$sql .= "WHERE language = '".strtoupper($lang)."' AND position = ".$page_info['position']." ";
$sql .= "AND level = ".LEVEL." AND menu = ".$page_info['menu'];

$get_content $database->query($sql);
$content $get_content->fetchRow();

if ($content && $content['visibility'] === 'public') {
$url WB_URL.PAGES_DIRECTORY.$content['link'].PAGE_EXTENSION;
}
else {
$url WB_URL.PAGES_DIRECTORY.'/'.strtolower($lang).PAGE_EXTENSION;
}
}
return 
$url;

?>



Just insert the code (without <?php ... ?>) into the droplet creator and call it with [[dropletname?lang=(code)]];