[HowTo] Weiterer Dropdown Sprachumschalter
Autor
Nachricht
Verfasst am: 17.11.2008 [12:16]
einpraegsam.net [Moderator] [Themenersteller] dabei seit: 17.01.2005 Beiträge: 8108
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 :: einpraegsam.net :: Follow Me :: XING profile :: conject
Verfasst am: 04.05.2009 [13:34]
ristic dabei seit: 21.02.2008 Beiträge: 145
Exzellent, genau das hab ich gebraucht. Danke erst mal! Hab es noch etwas erweitert, falls mal eine Sprache gelöscht wurde, funktioniert das Ganze leider nur wenn man im TS bei userFunc.lang etwas trickst. Mit diesen Änderungen im TS und im PHP vor der ersten foreach-Schleife sollte es klappen.
Typoscript: Zeilennummerierung:
An /
Aus
temp .languageswitcher =
COA
temp .languageswitcher {
10 .userFunc = user_langswitch->start
# was hier gesetzt wird wird auch nur angezeigt
10 .userFunc .lang = en,de_DE,fr,es,pl,fr_FR
# hier werden die richtigen IDs gesetzt, so kann auch nix schief laufen
10 .userFunc .id = 0 , 1 , 4 , 5 , 6 , 7
10 .userFunc .label = en:International ( English) ,de_DE:Deutschland ( Deutsch) ,fr:International ( Français)
}
Das vor die erste foreach-Schleife.
Php: Zeilennummerierung:
An /
Aus
// get the ids of the language from the TS and combine it
$this->id = t3lib_div::trimExplode(',', $conf['userFunc.']['id'], 1); // array with ids
$this->lang = array_combine($this->id, $this->lang);
Danke nochmal an Alex! Falls ich dazu komme, werd ich hierzu mal eine Extension erstellen.
Gruß
Daniel Life moves pretty fast. You don’t stop and look around once in a while, you could miss it. [Ferris Bueller]
Verfasst am: 09.06.2009 [11:22]
massel dabei seit: 06.07.2005 Beiträge: 1
Sprachwechsler funktioniert wunderbar, aber nun mault der Validator.
general entity "L" not defined and no default entity
Weiß jemand Rat?
Gruß Massel
TYPO3 4.3.2 jetzt testen
Testen Sie die neue TYPO3 Version 4.3.2 kostenlos für einen Monat
Entwicklerschulungen
Berlin: Mon., 12.04.10 - Mit., 14.04.10
Espelkamp: Mon., 17.05.10 - Mit., 19.05.10
Espelkamp: Mon., 15.03.10
Berlin: Mon., 19.04.10
Espelkamp: Mon., 22.03.10 - Die., 23.03.10
Berlin: Mon., 26.04.10 - Die., 27.04.10
Espelkamp: Die., 16.03.10
Berlin: Die., 20.04.10
Espelkamp: Mit., 17.03.10 - Fre., 19.03.10
Berlin: Mit., 21.04.10 - Fre., 23.04.10
Köln: Mon., 21.06.10 - Mit., 23.06.10
Espelkamp: Mit., 24.03.10 - Fre., 26.03.10
Berlin: Mit., 28.04.10 - Fre., 30.04.10
Espelkamp: Mon., 29.03.10 - Mit., 31.03.10
Berlin: Mon., 03.05.10 - Mit., 05.05.10