00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 include_once( 'lib/ezutils/classes/ezini.php' );
00030
00031
00032
00033
00034 function ezcurrentLanguage()
00035 {
00036 include_once( 'lib/ezlocale/classes/ezlocale.php' );
00037 $locale =& eZLocale::instance();
00038 return $locale->translationCode();
00039 }
00040
00041
00042
00043
00044
00045
00046
00047
00048 function ezinsertarguments( $text, $arguments )
00049 {
00050 if ( is_array( $arguments ) )
00051 {
00052 $replaceList = array();
00053 foreach ( $arguments as $argumentKey => $argumentItem )
00054 {
00055 if ( is_int( $argumentKey ) )
00056 $replaceList['%' . ( ($argumentKey%9) + 1 )] = $argumentItem;
00057 else
00058 $replaceList[$argumentKey] = $argumentItem;
00059 }
00060 $text = strtr( $text, $replaceList );
00061 }
00062 return $text;
00063 }
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 $ini =& eZINI::instance();
00074 $useTextTranslation = false;
00075 $hasFallback = false;
00076 if ( $ini->variable( 'RegionalSettings', 'TextTranslation' ) != 'disabled' )
00077 {
00078 $language = ezcurrentLanguage();
00079 $iniI18N =& eZINI::instance( "i18n.ini" );
00080 $fallbacks = $iniI18N->variable( 'TranslationSettings', 'FallbackLanguages' );
00081
00082 include_once( 'lib/ezutils/classes/ezextension.php' );
00083 $extensionBase = eZExtension::baseDirectory();
00084 $translationExtensions = $ini->variable( 'RegionalSettings', 'TranslationExtensions' );
00085
00086 if ( array_key_exists( $language, $fallbacks ) and $fallbacks[$language] )
00087 {
00088 if ( file_exists( 'share/translations/' . $fallbacks[$language] . '/translation.ts' ) )
00089 {
00090 $hasFallback = true;
00091 }
00092 else
00093 {
00094 foreach ( $translationExtensions as $translationExtension )
00095 {
00096 $extensionPath = $extensionBase . '/' . $translationExtension . '/translations/' . $fallbacks[$language] . '/translation.ts';
00097 if ( file_exists( $extensionPath ) )
00098 {
00099 $hasFallback = true;
00100 break;
00101 }
00102 }
00103 }
00104 }
00105 if ( file_exists( 'share/translations/' . $language . '/translation.ts' ) || $hasFallback )
00106 {
00107 $useTextTranslation = true;
00108 }
00109 else
00110 {
00111 foreach ( $translationExtensions as $translationExtension )
00112 {
00113 $extensionPath = $extensionBase . '/' . $translationExtension . '/translations/' . $language . '/translation.ts';
00114 if ( file_exists( $extensionPath ) )
00115 {
00116 $useTextTranslation = true;
00117 break;
00118 }
00119 }
00120 }
00121 }
00122
00123 include_once( 'lib/ezi18n/classes/eztranslatormanager.php' );
00124
00125 if ( $useTextTranslation || eZTranslatorManager::dynamicTranslationsEnabled() )
00126 {
00127 include_once( 'lib/ezi18n/classes/eztstranslator.php' );
00128
00129 function &ezi18n( $context, $source, $comment = null, $arguments = null )
00130 {
00131 $text = eZTranslateText( $context, $source, $comment, $arguments );
00132 return $text;
00133 }
00134
00135 function &ezx18n( $extension, $context, $source, $comment = null, $arguments = null )
00136 {
00137 $text = eZTranslateText( $context, $source, $comment, $arguments );
00138 return $text;
00139 }
00140
00141 function &eZTranslateText( $context, $source, $comment = null, $arguments = null )
00142 {
00143 $ini =& eZINI::instance();
00144 if ( $ini->variable( 'RegionalSettings', 'Locale' ) == 'eng-GB' )
00145 {
00146
00147
00148 $text = ezinsertarguments( $source, $arguments );
00149 return $text;
00150 }
00151
00152 $language = ezcurrentLanguage();
00153
00154 $file = 'translation.ts';
00155
00156
00157 $useCache = $ini->variable( 'RegionalSettings', 'TranslationCache' ) != 'disabled';
00158 eZTSTranslator::initialize( $context, $language, $file, $useCache );
00159
00160
00161
00162
00163 $developmentMode = $ini->variable( 'RegionalSettings', 'DevelopmentMode' ) != 'disabled';
00164 if ( $developmentMode )
00165 {
00166 include_once( 'lib/ezi18n/classes/ezborktranslator.php' );
00167 eZBorkTranslator::initialize();
00168 }
00169
00170 $man =& eZTranslatorManager::instance();
00171 $trans = $man->translate( $context, $source, $comment );
00172 if ( $trans !== null ) {
00173 $text = ezinsertarguments( $trans, $arguments );
00174 return $text;
00175 }
00176
00177 eZDebug::writeWarning( "No translation for file(translation.ts) in context($context): '$source' with comment($comment)", "ezi18n" );
00178 $text = ezinsertarguments( $source, $arguments );
00179 return $text;
00180 }
00181 }
00182 else
00183 {
00184 function ezi18n( $context, $source, $comment = null, $arguments = null )
00185 {
00186 return ezinsertarguments( $source, $arguments );
00187 }
00188
00189 function ezx18n( $extension, $context, $source, $comment = null, $arguments = null )
00190 {
00191 return ezinsertarguments( $source, $arguments );
00192 }
00193 }
00194
00195 ?>