Documentation TYPO3 par Ameos

lang.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00089 class language {
00090         var $lang='default';            // This is set to the language that is currently running for the user
00091         var $langSplit='default';       // Values like the labels in the tables.php-document are split by '|'. This values defines which language is represented by which position in the resulting array after splitting a value. (NOTICE: Obsolete concept!)
00092 
00093                 // Default charset in backend
00094         var $charSet = 'iso-8859-1';
00095 
00096                 // Array with alternative charsets for other languages. (Moved to t3lib_cs, Set from csConvObj!)
00097         var $charSetArray = array();
00098 
00099                 // This is the url to the TYPO3 manual
00100         var $typo3_help_url= 'http://www.typo3.com/man_uk/';
00101                 // Array with alternative URLs based on language.
00102         var $helpUrlArray = array(
00103                 'dk' => 'http://www.typo3.com/man_dk/',
00104         );
00105 
00106 
00107         var $moduleLabels = Array();    // Can contain labels and image references from the backend modules. Relies on t3lib_loadmodules to initialize modules after a global instance of $LANG has been created.
00108 
00109                 // Internal
00110         var $langSplitIndex=0;                  // Points to the position of the current language key as found in constant TYPO3_languages
00111         var $LL_files_cache=array();    // Internal cache for read LL-files
00112         var $LL_labels_cache=array();   // Internal cache for ll-labels (filled as labels are requested)
00113 
00114                 // Internal charset conversion:
00115         var $origCharSet='';            // If set, then it means that the this->charSet is set to a forced, common value for the WHOLE backend regardless of user language. And THIS variable will contain the original charset for the language labels. With ->csConvObj we must then convert the original charset to the charset used in the backend from now on.
00116         var $csConvObj;                         // An instance of the "t3lib_cs" class. May be used by any application.
00117 
00118 
00119 
00120 
00121 
00122 
00123 
00124 
00137         function init($lang,$altPath='')        {
00138 
00139                         // Initialize the conversion object:
00140                 $this->csConvObj = t3lib_div::makeInstance('t3lib_cs');
00141                 $this->charSetArray = $this->csConvObj->charSetArray;
00142 
00143                         // Internally setting the list of TYPO3 backend languages.
00144                 $this->langSplit=TYPO3_languages;
00145 
00146                         // Finding the requested language in this list based on the $lang key being inputted to this function.
00147                 $ls = explode('|',$this->langSplit);
00148                 while(list($i,$v)=each($ls))    {
00149                         if ($v==$lang)  {       // Language is found. Configure it:
00150                                 $this->langSplitIndex=$i;               // The index of the language as found in the TYPO3_languages list
00151                                 $this->lang = $lang;                    // The current language key
00152                                 if ($this->helpUrlArray[$this->lang])   $this->typo3_help_url=$this->helpUrlArray[$this->lang]; // The help URL if different from the default.
00153                                 if ($this->charSetArray[$this->lang])   $this->charSet=$this->charSetArray[$this->lang];                // The charset if different from the default.
00154                         }
00155                 }
00156 
00157                         // If a forced charset is used and different from the charset otherwise used:
00158                 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] && $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']!=$this->charSet)     {
00159                                 // Set the forced charset:
00160                         $this->origCharSet = $this->charSet;
00161                         $this->charSet = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'];
00162 
00163                         if ($this->charSet!='utf-8' && !$this->csConvObj->initCharset($this->charSet))          {
00164                                 t3lib_BEfunc::typo3PrintError ('The forced character set "'.$this->charSet.'" was not found in t3lib/csconvtbl/','Forced charset not found');
00165                                 exit;
00166                         }
00167                         if ($this->origCharSet!='utf-8' && !$this->csConvObj->initCharset($this->origCharSet))          {
00168                                 t3lib_BEfunc::typo3PrintError ('The original character set "'.$this->origCharSet.'" was not found in t3lib/csconvtbl/','Forced charset not found');
00169                                 exit;
00170                         }
00171                 }
00172         }
00173 
00182         function addModuleLabels($arr,$prefix)  {
00183                 if (is_array($arr))     {
00184                         reset($arr);
00185                         while(list($k,$larr)=each($arr))        {
00186                                 if (!isset($this->moduleLabels[$k]))    {
00187                                         $this->moduleLabels[$k]=array();
00188                                 }
00189                                 if (is_array($larr))    {
00190                                         reset($larr);
00191                                         while(list($l,$v)=each($larr))  {
00192                                                 $this->moduleLabels[$k][$prefix.$l]=$v;
00193                                         }
00194                                 }
00195                         }
00196                 }
00197         }
00198 
00208         function hscAndCharConv($lStr,$hsc)     {
00209                 $lStr = $hsc ? htmlspecialchars($lStr) : $lStr;
00210                 if ($this->origCharSet) {
00211                         $lStr = $this->csConvObj->conv($lStr,$this->origCharSet,$this->charSet,1);
00212                 }
00213                 return $lStr;
00214         }
00215 
00223         function makeEntities($str)     {
00224                         // Convert string to UTF-8:
00225                 if ($this->charSet!='utf-8')    $str = $this->csConvObj->utf8_encode($str,$this->charSet);
00226 
00227                         // Convert string back again, but using the full entity conversion:
00228                 $str = $this->csConvObj->utf8_to_entities($str);
00229                 return $str;
00230         }
00231 
00240         function JScharCode($str)       {
00241 
00242                         // Convert string to UTF-8:
00243                 if ($this->charSet!='utf-8')    $str = $this->csConvObj->utf8_encode($str,$this->charSet);
00244 
00245                         // Convert the UTF-8 string into a array of char numbers:
00246                 $nArr = $this->csConvObj->utf8_to_numberarray($str);
00247 
00248                 return 'String.fromCharCode('.implode(',',$nArr).')';
00249         }
00250 
00259         function getLL($index,$hsc=0)   {
00260                 // Get Local Language
00261                 if (strcmp($GLOBALS['LOCAL_LANG'][$this->lang][$index],''))     {
00262                         return $this->hscAndCharConv($GLOBALS['LOCAL_LANG'][$this->lang][$index], $hsc);        // Returns local label if not blank.
00263                 } else {
00264                         return $this->hscAndCharConv($GLOBALS['LOCAL_LANG']['default'][$index], $hsc);  // Returns default label
00265                 }
00266         }
00267 
00276         function getLLL($index,$LOCAL_LANG,$hsc=0)      {
00277                 // Get Local Language
00278                 if (strcmp($LOCAL_LANG[$this->lang][$index],''))        {
00279                         return $this->hscAndCharConv($LOCAL_LANG[$this->lang][$index], $hsc);   // Returns local label if not blank.
00280                 } else {
00281                         return $this->hscAndCharConv($LOCAL_LANG['default'][$index], $hsc);             // Returns default label
00282                 }
00283         }
00284 
00296         function sL($input,$hsc=0)      {
00297                 if (strcmp(substr($input,0,4),'LLL:'))  {       // Using obsolete 'language-splitted' labels:
00298                         $t = explode('|',$input);
00299                         $out = $t[$this->langSplitIndex] ? $t[$this->langSplitIndex] : $t[0];
00300                         return $this->hscAndCharConv($out, $hsc);
00301                 } else {        // LOCAL_LANG:
00302                         if (!isset($this->LL_labels_cache[$this->lang][$input])) {      // If cached label
00303                                 $restStr = trim(substr($input,4));
00304                                 $extPrfx='';
00305                                 if (!strcmp(substr($restStr,0,4),'EXT:'))       {       // ll-file refered to is found in an extension.
00306                                         $restStr = trim(substr($restStr,4));
00307                                         $extPrfx='EXT:';
00308                                 }
00309                                 $parts = explode(':',$restStr);
00310                                 $parts[0]=$extPrfx.$parts[0];
00311                                 if (!isset($this->LL_files_cache[$parts[0]]))   {       // Getting data if not cached
00312                                         $this->LL_files_cache[$parts[0]] = $this->readLLfile($parts[0]);
00313 
00314                                                 // If the current language is found in another file, load that as well:
00315                                         $lFileRef = $this->localizedFileRef($parts[0]);
00316                                         if ($lFileRef && is_string($this->LL_files_cache[$parts[0]][$this->lang]) && $this->LL_files_cache[$parts[0]][$this->lang]=='EXT')      {
00317                                                 $tempLL = $this->readLLfile($lFileRef);
00318                                                 $this->LL_files_cache[$parts[0]][$this->lang] = $tempLL[$this->lang];
00319                                         }
00320 
00321                                                 // Overriding file?
00322                                         if (isset($GLOBALS['TYPO3_CONF_VARS']['BE']['XLLfile'][$parts[0]]))     {
00323                                                 $ORarray = $this->readLLfile($GLOBALS['TYPO3_CONF_VARS']['BE']['XLLfile'][$parts[0]]);
00324                                                 $this->LL_files_cache[$parts[0]] = t3lib_div::array_merge_recursive_overrule($this->LL_files_cache[$parts[0]],$ORarray);
00325                                         }
00326                                 }
00327                                 $this->LL_labels_cache[$this->lang][$input] = $this->getLLL($parts[1],$this->LL_files_cache[$parts[0]]);
00328                         }
00329                         return $hsc ? t3lib_div::deHSCentities(htmlspecialchars($this->LL_labels_cache[$this->lang][$input])) : $this->LL_labels_cache[$this->lang][$input]; // For the cached output charset conversion has already happend! So perform HSC right here.
00330                 }
00331         }
00332 
00340         function loadSingleTableDescription($table)     {
00341                 global $TCA_DESCR;
00342 
00343                 if (is_array($TCA_DESCR[$table])
00344                                 && !isset($TCA_DESCR[$table]['columns'])
00345                                 && is_array($TCA_DESCR[$table]['refs']))         {      // First the 'table' cannot already be loaded in [columns] and secondly there must be a references to locallang files available in [refs]
00346 
00347                                 // Init $TCA_DESCR for $table-key
00348                         $TCA_DESCR[$table]['columns']=array();
00349 
00350                                 // Get local-lang for each file in $TCA_DESCR[$table]['refs'] as they are ordered.
00351                         foreach ($TCA_DESCR[$table]['refs'] as $llfile) {
00352                                 $LOCAL_LANG = $this->includeLLFile($llfile,0,1);
00353 
00354                                         // Traverse all keys
00355                                 if (is_array($LOCAL_LANG['default']))   {
00356                                         foreach($LOCAL_LANG['default'] as $lkey => $lVal)       {
00357 
00358                                                         // exploding by '.':
00359                                                         // 0 => fieldname,
00360                                                         // 1 => type from (alttitle,description,details,syntax,image_descr,image,seeAlso),
00361                                                         // 2 => special instruction, see switch construct
00362                                                 $kParts = explode('.',$lkey);
00363 
00364                                                         // Detecting 'hidden' labels, converting to normal fieldname
00365                                                 if ($kParts[0]=='_')    $kParts[0]='';
00366                                                 if (substr($kParts[0],0,1)=='_')        { $kParts[0] = substr($kParts[0],1); }
00367 
00368                                                         // Add label:
00369                                                 switch((string)$kParts[2])      {
00370                                                         case '+':       // adding
00371                                                                 $TCA_DESCR[$table]['columns'][$kParts[0]][$kParts[1]].= chr(10).$lVal;
00372                                                         break;
00373                                                         default:        // Substituting:
00374                                                                 $TCA_DESCR[$table]['columns'][$kParts[0]][$kParts[1]] = $lVal;
00375                                                         break;
00376                                                 }
00377                                         }
00378                                 }
00379                         }
00380                 }
00381         }
00382 
00392         function includeLLFile($fileRef,$setGlobal=1,$mergeLocalOntoDefault=0)  {
00393                         // Configure for global flag:
00394                 if ($setGlobal) {
00395                         global $LOCAL_LANG;
00396                 }
00397 
00398                         // Get default file:
00399                 $llang = $this->readLLfile($fileRef);
00400 
00401                 if (count($llang))      {
00402 
00403                         $LOCAL_LANG = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG,$llang);
00404 
00405                                 // Localized addition?
00406                         $lFileRef = $this->localizedFileRef($fileRef);
00407                         if ($lFileRef && (string)$LOCAL_LANG[$this->lang]=='EXT')       {
00408                                 $llang = $this->readLLfile($lFileRef);
00409                                 $LOCAL_LANG = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG,$llang);
00410                         }
00411 
00412                                 // Overriding file?
00413                         if (isset($GLOBALS['TYPO3_CONF_VARS']['BE']['XLLfile'][$fileRef]))      {
00414                                 $ORarray = $this->readLLfile($GLOBALS['TYPO3_CONF_VARS']['BE']['XLLfile'][$fileRef]);
00415                                 $LOCAL_LANG = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG,$ORarray);
00416                         }
00417 
00418                                 // Merge local onto default:
00419                         if ($mergeLocalOntoDefault && strcmp($this->lang,'default') && is_array($LOCAL_LANG[$this->lang]) && is_array($LOCAL_LANG['default']))  {
00420                                 $LOCAL_LANG['default'] = array_merge($LOCAL_LANG['default'],$LOCAL_LANG[$this->lang]);  // array_merge can be used so far the keys are not numeric - which we assume they are not...
00421                                 unset($LOCAL_LANG[$this->lang]);
00422                         }
00423                 }
00424 
00425                         // Return value if not global is set.
00426                 if (!$setGlobal)        {
00427                         return $LOCAL_LANG;
00428                 }
00429         }
00430 
00437         function readLLfile($fileRef)   {
00438                 return t3lib_div::readLLfile($fileRef,$this->lang);
00439         }
00440 
00447         function localizedFileRef($fileRef)     {
00448                 if ($this->lang!='default' && substr($fileRef,-4)=='.php')      {
00449                         return substr($fileRef,0,-4).'.'.$this->lang.'.php';
00450                 }
00451         }
00452 }
00453 
00454 // Include extension to the template class?
00455 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/lang/lang.php'])       {
00456         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/lang/lang.php']);
00457 }
00458 ?>


Généré par Le spécialiste TYPO3 avec  doxygen 1.4.6