[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/common/ -> i18n.php (source)

   1  <?php
   2  //
   3  // Created on: <06-Jul-2003 15:52:54 amos>
   4  //
   5  // SOFTWARE NAME: eZ publish
   6  // SOFTWARE RELEASE: 3.9.0
   7  // BUILD VERSION: 17785
   8  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
   9  // SOFTWARE LICENSE: GNU General Public License v2.0
  10  // NOTICE: >
  11  //   This program is free software; you can redistribute it and/or
  12  //   modify it under the terms of version 2.0  of the GNU General
  13  //   Public License as published by the Free Software Foundation.
  14  //
  15  //   This program is distributed in the hope that it will be useful,
  16  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  17  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18  //   GNU General Public License for more details.
  19  //
  20  //   You should have received a copy of version 2.0 of the GNU General
  21  //   Public License along with this program; if not, write to the Free
  22  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  23  //   MA 02110-1301, USA.
  24  //
  25  //
  26  
  27  include_once ( 'lib/ezutils/classes/ezini.php' );
  28  
  29  /*!
  30   \return the current language used.
  31  */
  32  function ezcurrentLanguage()
  33  {
  34      include_once ( 'lib/ezlocale/classes/ezlocale.php' );
  35      $locale =& eZLocale::instance();
  36      return $locale->translationCode();
  37  }
  38  
  39  /*!
  40   Replaces keys found in \a $text with values in \a $arguments.
  41   If \a $arguments is an associative array it will use the argument
  42   keys as replacement keys. If not it will convert the index to
  43   a key looking like %n, where n is a number between 1 and 9.
  44   Returns the new string.
  45  */
  46  function ezinsertarguments( $text, $arguments )
  47  {
  48      if ( is_array( $arguments ) )
  49      {
  50          $replaceList = array();
  51          foreach ( $arguments as $argumentKey => $argumentItem )
  52          {
  53              if ( is_int( $argumentKey ) )
  54                  $replaceList['%' . ( ($argumentKey%9) + 1 )] = $argumentItem;
  55              else
  56                  $replaceList[$argumentKey] = $argumentItem;
  57          }
  58          $text = strtr( $text, $replaceList );
  59      }
  60      return $text;
  61  }
  62  
  63  /*!
  64   Translates the source \a $source with context \a $context and optional comment \a $comment
  65   and returns the translation.
  66   Uses eZTranslatorMananger::translate() to do the actual translation.
  67  
  68   If the site.ini settings RegionalSettings/TextTranslation is set to disabled this function
  69   will only return the source text.
  70  */
  71  $ini =& eZINI::instance();
  72  $useTextTranslation = false;
  73  $hasFallback = false;
  74  if ( $ini->variable( 'RegionalSettings', 'TextTranslation' ) != 'disabled' )
  75  {
  76      $language = ezcurrentLanguage();
  77      $iniI18N =& eZINI::instance( "i18n.ini" );
  78      $fallbacks = $iniI18N->variable( 'TranslationSettings', 'FallbackLanguages' );
  79  
  80      include_once ( 'lib/ezutils/classes/ezextension.php' );
  81      $extensionBase = eZExtension::baseDirectory();
  82      $translationExtensions = $ini->variable( 'RegionalSettings', 'TranslationExtensions' );
  83  
  84      if ( array_key_exists( $language,  $fallbacks ) and $fallbacks[$language] )
  85      {
  86          if ( file_exists( 'share/translations/' . $fallbacks[$language] . '/translation.ts' ) )
  87          {
  88              $hasFallback = true;
  89          }
  90          else
  91          {
  92              foreach ( $translationExtensions as $translationExtension )
  93              {
  94                  $extensionPath = $extensionBase . '/' . $translationExtension . '/translations' . $fallbacks[$language] . '/translation.ts';
  95                  if ( file_exists( $extensionPath ) )
  96                  {
  97                      $hasFallback = true;
  98                      break;
  99                  }
 100              }
 101          }
 102      }
 103      if ( file_exists( 'share/translations/' . $language . '/translation.ts' ) || $hasFallback )
 104      {
 105          $useTextTranslation = true;
 106      }
 107      else
 108      {
 109          foreach ( $translationExtensions as $translationExtension )
 110          {
 111              $extensionPath = $extensionBase . '/' . $translationExtension . '/translations' . $language . '/translation.ts';
 112              if ( file_exists( $extensionPath ) )
 113              {
 114                  $useTextTranslation = true;
 115                  break;
 116              }
 117          }
 118      }
 119  
 120  
 121      if ( $language != "eng-GB" ) // eng-GB does not need translation
 122      {
 123          include_once ( 'lib/ezi18n/classes/eztranslatormanager.php' );
 124          include_once ( 'lib/ezi18n/classes/eztstranslator.php' );
 125      }
 126  }
 127  
 128  if ( $useTextTranslation )
 129  {
 130      function &ezi18n( $context, $source, $comment = null, $arguments = null )
 131      {
 132          $text = eZTranslateText( $context, $source, $comment, $arguments );
 133          return $text;
 134      }
 135  
 136      function &ezx18n( $extension, $context, $source, $comment = null, $arguments = null )
 137      {
 138          $text = eZTranslateText( $context, $source, $comment, $arguments );
 139          return $text;
 140      }
 141  
 142      function &eZTranslateText( $context, $source, $comment = null, $arguments = null )
 143      {
 144          $language = ezcurrentLanguage();
 145  
 146          $file = 'translation.ts';
 147  
 148          // translation.ts translation
 149          $ini =& eZINI::instance();
 150          $useCache = $ini->variable( 'RegionalSettings', 'TranslationCache' ) != 'disabled';
 151          eZTSTranslator::initialize( $context, $language, $file, $useCache );
 152  
 153          // Bork translation: Makes it easy to see what is not translated.
 154          // If no translation is found in the eZTSTranslator, a Bork translation will be returned.
 155          // Bork is different than, but similar to, eng-GB, and is enclosed in square brackets [].
 156          $developmentMode = $ini->variable( 'RegionalSettings', 'DevelopmentMode' ) != 'disabled';
 157          if ( $developmentMode )
 158          {
 159              include_once ( 'lib/ezi18n/classes/ezborktranslator.php' );
 160              eZBorkTranslator::initialize();
 161          }
 162  
 163          $man =& eZTranslatorManager::instance();
 164          $trans = $man->translate( $context, $source, $comment );
 165          if ( $trans !== null ) {
 166              $text = ezinsertarguments( $trans, $arguments );
 167              return $text;
 168          }
 169  
 170          eZDebug::writeWarning( "No translation for file(translation.ts) in context($context): '$source' with comment($comment)", "ezi18n" );
 171          $text = ezinsertarguments( $source, $arguments );
 172          return $text;
 173      }
 174  }
 175  else
 176  {
 177      function ezi18n( $context, $source, $comment = null, $arguments = null )
 178      {
 179          return ezinsertarguments( $source, $arguments );
 180      }
 181  
 182      function ezx18n( $extension, $context, $source, $comment = null, $arguments = null )
 183      {
 184          return ezinsertarguments( $source, $arguments );
 185      }
 186  }
 187  
 188  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7