[HowTo] Weiterer Dropdown Sprachumschalter wurde Beantwortet

Autor Nachricht
Verfasst am: 17.11.2008 [12:16]
einpraegsam.net

[Moderator]
dabei seit: 17.01.2005
Beiträge: 6039

über 5000 Posts
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

  1. includeLibs.user_langswitch = fileadmin/user_langswitch.php
  2.  
  3. temp.languageswitcher = COA
  4. temp.languageswitcher {
  5.         10 = USER_INT
  6.         10.userFunc = user_langswitch->start
  7.         10.userFunc.lang = en,de,es,pt,ru,me
  8.         10.userFunc.label = en:English (Americas/Europe),me:English (Middle East/Asia-Pac),de:Deutsch (German), ru:Russian (Russian), es:, pt:,
  9. }
  10.  
  11. page.10.marks.languageswitcher < temp.languageswitcher


userFunc:
Php:Zeilennummerierung:  An / Aus

  1. <?php
  2.  
  3.         class user_langswitch {
  4.                
  5.                 var $debug = 0; // debug output (viewable code)
  6.        
  7.                 // Main function for languageswitcher selectbox
  8.                 function start($content='', $conf=array()) {
  9.                         // config
  10.                         global $TSFE;
  11.             $this->cObj = $TSFE->cObj; // cObject
  12.                         $this->label = array(); $code = $all = ''; // init
  13.                         $this->lang = t3lib_div::trimExplode(',', $conf['userFunc.']['lang'], 1); // array with languages
  14.                         $tmp_label = t3lib_div::trimExplode(',', $conf['userFunc.']['label'], 1); // array with labels
  15.                         foreach ($tmp_label as $key => $value) { // one loop for every label
  16.                                 $tmp_curlabel = t3lib_div::trimExplode(':', $value, 1); // split on :
  17.                                 $this->label[$tmp_curlabel[0]] = $tmp_curlabel[1]; // e.g. "en" => "switch to english"
  18.                         }
  19.                
  20.                         // let's go
  21.                         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)
  22.                                 foreach ($this->label as $key => $value) { // one loop for every allowed label
  23.                                         if ($value) {
  24.                                                 $code .= '<option value="' . $this->makeLink($key) . '"' . ($this->lang[$_GET['L']] == $key ? ' selected="selected"' : '') . '>'; // option prefix
  25.                                                 $code .= $value; // value
  26.                                                 $code .= '</option>'; // option postfix
  27.                                         }
  28.                                 }
  29.                                
  30.                                 $all .= $this->debug ? '<textarea cols="50" rows="20">' : '';
  31.                                 $all .= '<form name="language" action="" class="languageselectform">';
  32.                                 $all .= '<select name="select" onchange="goto(this.form)" class="languageselect">';
  33.                                 $all .= $code;
  34.                                 $all .= '</select>';
  35.                                 $all .= '</form>';
  36.                                 $all .= $this->addJS();
  37.                                 $all .= $this->debug ? '</textarea>' : '';
  38.                         }
  39.                        
  40.                         // return
  41.                         return $all;
  42.                 }
  43.                
  44.                
  45.                 // Function makeLink() generate localized link from language key (en, de)
  46.                 function makeLink($key) {
  47.                         $tmp_lang = array_flip($this->lang); // get array like en=>0, de=>1
  48.                         return '/'.$this->cObj->typolink('x', array('returnLast' => 'url', 'parameter' => $GLOBALS['TSFE']->id, 'additionalParams' => '&L='.$tmp_lang[$key])); // return link
  49.                 }
  50.                
  51.                
  52.                 // Add javascript for redirection
  53.                 function addJS() {
  54.                         $js = '<script type="text/javascript">
  55.                                                 function goto(form) {
  56.                                                         var index = form.select.selectedIndex;
  57.                                                         if (form.select.options[index].value != "0") {
  58.                                                                 location = form.select.options[index].value;
  59.                                                         }
  60.                                                 }
  61.                                         </script>
  62.                                 ';
  63.                         return $js;
  64.                 }
  65.        
  66.        
  67.         }
  68.  
  69. ?>


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 Version 4.2.3 testen

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

  • 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