本文整理汇总了PHP中eZTranslatorManager::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP eZTranslatorManager::instance方法的具体用法?PHP eZTranslatorManager::instance怎么用?PHP eZTranslatorManager::instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZTranslatorManager
的用法示例。
在下文中一共展示了eZTranslatorManager::instance方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initialize
static function initialize()
{
if (!isset($GLOBALS['eZ1337Translator']) || !$GLOBALS['eZ1337Translator'] instanceof eZ1337Translator) {
$GLOBALS['eZ1337Translator'] = new eZ1337Translator();
}
$man = eZTranslatorManager::instance();
$man->registerHandler($GLOBALS['eZ1337Translator']);
return $GLOBALS['eZ1337Translator'];
}
示例2: i18nTrans
function i18nTrans($operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
{
// i18n( $input, $context, $comment, $arguments )
// Check if if the three first parameters are constants, if not we cannot compile it
foreach (array_slice($parameters, 0, 3) as $parameter) {
if ($parameter !== null && !eZTemplateNodeTool::isConstantElement($parameter)) {
return false;
}
}
$value = eZTemplateNodeTool::elementConstantValue($parameters[0]);
$numParameters = count($parameters);
$context = $numParameters > 1 ? eZTemplateNodeTool::elementConstantValue($parameters[1]) : null;
$comment = $numParameters > 2 ? eZTemplateNodeTool::elementConstantValue($parameters[2]) : null;
if ($numParameters < 4) {
return array(eZTemplateNodeTool::createStringElement(ezpI18n::tr($context, $value, $comment, null)));
}
$values = array();
$ini = eZINI::instance();
if ($ini->variable('RegionalSettings', 'TextTranslation') != 'disabled') {
$language = eZLocale::instance()->localeFullCode();
if ($language != "eng-GB") {
$file = 'translation.ts';
$ini = eZINI::instance();
$useCache = $ini->variable('RegionalSettings', 'TranslationCache') != 'disabled';
eZTSTranslator::initialize($context, $language, $file, $useCache);
$man = eZTranslatorManager::instance();
$newValue = $man->translate($context, $value, $comment);
if ($newValue) {
$value = $newValue;
}
}
}
$values[] = array(eZTemplateNodeTool::createStringElement($value));
$values[] = $parameters[3];
$code = '%tmp1% = array();' . "\n" . 'foreach ( %2% as %tmp2% => %tmp3% )' . "\n" . '{' . "\n" . ' if ( is_int( %tmp2% ) )' . "\n" . ' %tmp1%[\'%\' . ( (%tmp2%%9) + 1 )] = %tmp3%;' . "\n" . ' else' . "\n" . ' %tmp1%[%tmp2%] = %tmp3%;' . "\n" . '}' . "\n" . '%output% = strtr( %1%, %tmp1% );' . "\n";
return array(eZTemplateNodeTool::createCodePieceElement($code, $values, false, 3));
}
示例3: findMessage
function findMessage( $context, $source, $comment = null )
{
$man = eZTranslatorManager::instance();
$translation = $this->shuffleText( $source );
return $man->createMessage( $context, $source, $comment, $translation );
}
示例4: remove
/**
* Removes the translation message with context $context and source $source.
*
* If you have the translation key use removeKey() instead.
*
* @param string $context
* @param string $source
* @param string $message
*
* @return bool true if the message was removed, false otherwise
*/
function remove($context, $source, $message = null)
{
if ($context == "") {
$context = "default";
}
$man = eZTranslatorManager::instance();
$key = $man->createKey($context, $source, $message);
if (isset($this->Messages[$key])) {
unset($this->Messages[$key]);
}
}
示例5: translateText
/**
* Translates the source \a $source with context \a $context and optional comment \a $comment
* and returns the translation if locale code is not eng-GB.
* Uses {@link eZTranslatorMananger::translate()} to do the actual translation
*
* Example:
* translateText( 'content/view', 'There are %count nodes in this list out of %total total nodes.', 'Children view of nodes for whole site', array( '%count' => $c, '%total' => $t ) );
*
* @param string $context
* @param string $source
* @param string|null $comment
* @param array|null $arguments
* @return string
*/
protected static function translateText($context, $source, $comment = null, $arguments = null)
{
$localeCode = eZLocale::instance()->localeFullCode();
if ($localeCode == 'eng-GB') {
// we don't have ts-file for 'eng-GB'.
return self::insertArguments($source, $arguments);
}
$ini = eZINI::instance();
$useCache = $ini->variable('RegionalSettings', 'TranslationCache') != 'disabled';
eZTSTranslator::initialize($context, $localeCode, 'translation.ts', $useCache);
// Bork translation: Makes it easy to see what is not translated.
// If no translation is found in the eZTSTranslator, a Bork translation will be returned.
// Bork is different than, but similar to, eng-GB, and is enclosed in square brackets [].
$developmentMode = $ini->variable('RegionalSettings', 'DevelopmentMode') != 'disabled';
if ($developmentMode) {
eZBorkTranslator::initialize();
}
$man = eZTranslatorManager::instance();
$trans = $man->translate($context, $source, $comment);
if ($trans !== null) {
return self::insertArguments($trans, $arguments);
}
if ($comment != null and strlen($comment) > 0) {
eZDebug::writeDebug("Missing translation for message in context: '{$context}' with comment: '{$comment}'. The untranslated message is: '{$source}'", __METHOD__);
} else {
eZDebug::writeDebug("Missing translation for message in context: '{$context}'. The untranslated message is: '{$source}'", __METHOD__);
}
return self::insertArguments($source, $arguments);
}
示例6: registerHandler
static function registerHandler($handler)
{
$instance = eZTranslatorManager::instance();
$instance->Handlers[] = $handler;
}
示例7: initialize
static function initialize( $context, $locale, $useCache = true )
{
if ( !isset( $GLOBALS['eZBorkTranslator'] ) ||
!( $GLOBALS['eZBorkTranslator'] instanceof eZBorkTranslator ) )
{
$GLOBALS['eZBorkTranslator'] = new eZBorkTranslator();
}
$man = eZTranslatorManager::instance();
$man->registerHandler( $GLOBALS['eZBorkTranslator'] );
return $GLOBALS['eZBorkTranslator'];
}
示例8: translateText
/**
* Translates the source \a $source with context \a $context and optional comment \a $comment
* and returns the translation if locale code is not eng-GB.
* Uses {@link eZTranslatorMananger::translate()} to do the actual translation
*
* Example:
* translateText( 'content/view', 'There are %count nodes in this list out of %total total nodes.', 'Children view of nodes for whole site', array( '%count' => $c, '%total' => $t ) );
*
* @param string $context
* @param string $source
* @param string|null $comment
* @param array|null $arguments
* @return string
*/
protected static function translateText( $context, $source, $comment = null, $arguments = null )
{
$localeCode = eZLocale::instance()->localeFullCode();
if ( $localeCode == 'eng-GB' )
{
// we don't have ts-file for 'eng-GB'.
return self::insertArguments( $source, $arguments );
}
// Load all TranslatorHandlers from settings
$ini = eZINI::instance();
$useCache = $ini->variable( 'RegionalSettings', 'TranslationCache' ) != 'disabled';
$handlerClassList = $ini->variable( 'RegionalSettings', 'TranslatorHandlers' );
foreach( $handlerClassList as $handlerClass )
{
call_user_func_array( array( $handlerClass, 'initialize' ), array( $context, $localeCode, $useCache ) );
}
// Bork translation: Makes it easy to see what is not translated.
// If no translation is found in the eZTSTranslator, a Bork translation will be returned.
// Bork is different than, but similar to, eng-GB, and is enclosed in square brackets [].
$developmentMode = $ini->variable( 'RegionalSettings', 'DevelopmentMode' ) != 'disabled';
if ( $developmentMode && ! in_array( 'eZBorkTranslator', $handlerClassList ) )
{
eZBorkTranslator::initialize( $context, $localeCode, $useCache );
}
$man = eZTranslatorManager::instance();
$trans = $man->translate( $context, $source, $comment );
if ( $trans !== null ) {
return self::insertArguments( $trans, $arguments );
}
if ( $comment != null and strlen( $comment ) > 0 )
eZDebug::writeDebug( "Missing translation for message in context: '$context' with comment: '$comment'. The untranslated message is: '$source'", __METHOD__ );
else
eZDebug::writeDebug( "Missing translation for message in context: '$context'. The untranslated message is: '$source'", __METHOD__ );
return self::insertArguments( $source, $arguments );
}