So, vermutlich gibt es so etwas schon in der einen oder anderen Art - aber vielleicht kann es ja trotzdem jemand brauchen:
Beispiel:
http://www.conject.com/en/diverse-daten/test/languageswitcher.html
Typoscript:
includeLibs.user_langswitch = fileadmin/user_langswitch.php
temp.languageswitcher = COA
temp.languageswitcher {
10 = USER_INT
10.userFunc = user_langswitch->start
10.userFunc.lang = en,de,es,pt,ru,me
10.userFunc.label = en:English (Americas/Europe),me:English (Middle East/Asia-Pac),de:Deutsch (German), ru:Russian (Russian), es:, pt:,
}
page.10.marks.languageswitcher < temp.languageswitcher
userFunc:
<?php
class user_langswitch {
var $debug = 0; // debug output (viewable code)
// Main function for languageswitcher selectbox
function start($content='', $conf=array()) {
// config
global $TSFE;
$this->cObj = $TSFE->cObj; // cObject
$this->label = array(); $code = $all = ''; // init
$this->lang = t3lib_div::trimExplode(',', $conf['userFunc.']['lang'], 1); // array with languages
$tmp_label = t3lib_div::trimExplode(',', $conf['userFunc.']['label'], 1); // array with labels
foreach ($tmp_label as $key => $value) { // one loop for every label
$tmp_curlabel = t3lib_div::trimExplode(':', $value, 1); // split on :
$this->label[$tmp_curlabel[0]] = $tmp_curlabel[1]; // e.g. "en" => "switch to english"
}
// let's go
if (is_array($this->label) && count($this->label) > 0 && is_array($this->lang) && count($this->lang) > 0) { // only if settings available (label and lang keys)
foreach ($this->label as $key => $value) { // one loop for every allowed label
if ($value) {
$code .= '<option value="' . $this->makeLink($key) . '"' . ($this->lang[$_GET['L']] == $key ? ' selected="selected"' : '') . '>'; // option prefix
$code .= $value; // value
$code .= '</option>'; // option postfix
}
}
$all .= $this->debug ? '<textarea cols="50" rows="20">' : '';
$all .= '<form name="language" action="" class="languageselectform">';
$all .= '<select name="select" onchange="goto(this.form)" class="languageselect">';
$all .= $code;
$all .= '</select>';
$all .= '</form>';
$all .= $this->addJS();
$all .= $this->debug ? '</textarea>' : '';
}
// return
return $all;
}
// Function makeLink() generate localized link from language key (en, de)
function makeLink($key) {
$tmp_lang = array_flip($this->lang); // get array like en=>0, de=>1
return '/'.$this->cObj->typolink('x', array('returnLast' => 'url', 'parameter' => $GLOBALS['TSFE']->id, 'additionalParams' => '&L='.$tmp_lang[$key])); // return link
}
// Add javascript for redirection
function addJS() {
$js = '<script type="text/javascript">
function goto(form) {
var index = form.select.selectedIndex;
if (form.select.options[index].value != "0") {
location = form.select.options[index].value;
}
}
</script>
';
return $js;
}
}
?>
Installation:
- Datei user_langswitch.php in fileadmin anlegen (beispielsweise)
- Per TS Datei einbinden
- Mit userFunc auf Klasse zugreifen und Sprachen und Labels definieren
- Wichtig: Reihenfolge von lang (bei mir &L=0 ist en, &L=1 ist de, etc...)
Grüße, Alex