Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezpi18n.php
Go to the documentation of this file.
1 <?php
11 class ezpI18n
12 {
19 protected static $isEnabled = null;
20
31 protected static function insertArguments( $text, $arguments )
32 {
33 if ( is_array( $arguments ) )
34 {
35 $replaceList = array();
36 foreach ( $arguments as $argumentKey => $argumentItem )
37 {
38 if ( is_int( $argumentKey ) )
39 $replaceList['%' . ( ($argumentKey%9) + 1 )] = $argumentItem;
40 else
41 $replaceList[$argumentKey] = $argumentItem;
42 }
43 $text = strtr( $text, $replaceList );
44 }
45 return $text;
46 }
47
53 protected static function isEnabled()
54 {
55 if ( self::$isEnabled === null )
56 {
57 $ini = eZINI::instance();
58 $useTextTranslation = $ini->variable( 'RegionalSettings', 'TextTranslation' ) != 'disabled';
59 self::$isEnabled = $useTextTranslation || eZTranslatorManager::dynamicTranslationsEnabled();
60 }
61 return self::$isEnabled;
62 }
63
67 public static function reset()
68 {
69 self::$isEnabled = null;
70 }
71
86 public static function tr( $context, $source, $comment = null, $arguments = null )
87 {
88 if ( self::isEnabled() )
89 {
90 return self::translateText( $context, $source, $comment, $arguments );
91 }
92 return self::insertArguments( $source, $arguments );
93 }
94
109 protected static function translateText( $context, $source, $comment = null, $arguments = null )
110 {
111 $localeCode = eZLocale::instance()->localeFullCode();
112 if ( $localeCode == 'eng-GB' )
113 {
114 // we don't have ts-file for 'eng-GB'.
115 return self::insertArguments( $source, $arguments );
116 }
117
118 $ini = eZINI::instance();
119 $useCache = $ini->variable( 'RegionalSettings', 'TranslationCache' ) != 'disabled';
120 eZTSTranslator::initialize( $context, $localeCode, 'translation.ts', $useCache );
121
122 // Bork translation: Makes it easy to see what is not translated.
123 // If no translation is found in the eZTSTranslator, a Bork translation will be returned.
124 // Bork is different than, but similar to, eng-GB, and is enclosed in square brackets [].
125 $developmentMode = $ini->variable( 'RegionalSettings', 'DevelopmentMode' ) != 'disabled';
126 if ( $developmentMode )
127 {
128 eZBorkTranslator::initialize();
129 }
130
131 $man = eZTranslatorManager::instance();
132 $trans = $man->translate( $context, $source, $comment );
133 if ( $trans !== null ) {
134 return self::insertArguments( $trans, $arguments );
135 }
136
137 if ( $comment != null and strlen( $comment ) > 0 )
138 eZDebug::writeDebug( "Missing translation for message in context: '$context' with comment: '$comment'. The untranslated message is: '$source'", __METHOD__ );
139 else
140 eZDebug::writeDebug( "Missing translation for message in context: '$context'. The untranslated message is: '$source'", __METHOD__ );
141
142 return self::insertArguments( $source, $arguments );
143 }
144 }
145
146 ?>
eZBorkTranslator\initialize
static initialize()
Definition: ezborktranslator.php:127
eZDebug\writeDebug
static writeDebug( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:588
eZLocale\instance
static instance( $localeString=false)
Definition: ezlocale.php:1536
eZTSTranslator\initialize
static initialize( $context, $locale, $filename, $useCache=true)
Definition: eztstranslator.php:53
eZTranslatorManager\dynamicTranslationsEnabled
static dynamicTranslationsEnabled()
Definition: eztranslatormanager.php:193
eZTranslatorManager\instance
static instance()
Definition: eztranslatormanager.php:127
ezpI18n
Definition: ezpi18n.php:12
ezpI18n\translateText
static translateText( $context, $source, $comment=null, $arguments=null)
Definition: ezpi18n.php:109
ezpI18n\$isEnabled
static $isEnabled
Definition: ezpi18n.php:19
ezpI18n\insertArguments
static insertArguments( $text, $arguments)
Definition: ezpi18n.php:31
ezpI18n\isEnabled
static isEnabled()
Definition: ezpi18n.php:53
ezpI18n\reset
static reset()
Definition: ezpi18n.php:67
ezpI18n\tr
static tr( $context, $source, $comment=null, $arguments=null)
Definition: ezpi18n.php:86
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.