[HowTo] Weiterer Dropdown Sprachumschalter
Autor
Nachricht
Verfasst am: 17.11.2008 [12:16]
einpraegsam.net [Moderator] dabei seit: 17.01.2005 Beiträge: 6039
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:
Typoscript: Zeilennummerierung:
An /
Aus
includeLibs .user_langswitch = fileadmin/user_langswitch.php
temp .languageswitcher =
COA
temp .languageswitcher {
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: Zeilennummerierung:
An /
Aus
<?php
class user_langswitch {
var $debug = 0 ; // debug output (viewable code)
// Main function for languageswitcher selectbox
function start
( $content =
'' ,
$conf =
array ( ) ) {
// config
$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 Powermail :: Einprägsam :: Smokethis :: Mein Profil bei XING :: conject
TYPO3 Ver. 4.2.3 testen
Testen Sie die neue TYPO3 Version 4.2.3 kostenlos für einen Monat Jetzt kostenlos testen
TYPO3 Schulungen
Espelkamp: Mon., 16.02.09
Berlin: Mon., 23.03.09
Berlin: Mit., 07.01.09 - Fre., 09.01.09
Köln: Mit., 28.01.09 - Fre., 30.01.09
Espelkamp: Mit., 18.02.09 - Fre., 20.02.09
Würzburg: Mon., 11.05.09 - Mit., 13.05.09
Berlin: Mon., 12.01.09 - Mit., 14.01.09
Espelkamp: Mon., 23.02.09 - Mit., 25.02.09