当前位置: 首页>>代码示例>>PHP>>正文


PHP Translator::translate方法代码示例

本文整理汇总了PHP中Translator::translate方法的典型用法代码示例。如果您正苦于以下问题:PHP Translator::translate方法的具体用法?PHP Translator::translate怎么用?PHP Translator::translate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Translator的用法示例。


在下文中一共展示了Translator::translate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: renderContent

 protected function renderContent($api, $unit, $moduleInfo)
 {
     $items = array();
     // get breadcrumb trail
     if ($api->isPage()) {
         $startPageId = $api->getFormValue($unit, 'navStart');
         // get all page ids in current navigator
         $nav = $api->getNavigation();
         $pageIds = $nav->getNavigatorIds($nav->getCurrentPageId());
         // only show until start page if set
         if (!empty($startPageId) && in_array($startPageId, $pageIds)) {
             $pageIds = array_slice($pageIds, array_search($startPageId, $pageIds) + 1);
         }
         if (is_array($pageIds)) {
             foreach ($pageIds as $pageId) {
                 $page = $nav->getPage($pageId);
                 // echo "\nPAGE: {$page->getTitle()} {$page->getUrl()}";
                 $items[] = array('href' => $api->isEditMode() ? 'javascript:void(0)' : $page->getUrl(), 'title' => $page->getNavigationTitle());
             }
         }
     } else {
         if ($api->isEditMode() || $api->isPreviewMode()) {
             // demo nav items in preview and edit mode
             $i18n = new Translator($api, $moduleInfo);
             $items = array(array('href' => 'javascript:void(0)', 'title' => $i18n->translate('testdata.page') . ' 1'), array('href' => 'javascript:void(0)', 'title' => $i18n->translate('testdata.page') . ' 2'), array('href' => 'javascript:void(0)', 'title' => $i18n->translate('testdata.page') . ' 3'));
         }
     }
     $spacerTag = $this->getBreadcrumbSpacerTag($api->getFormValue($unit, 'spacer'));
     $trail = array();
     foreach ($items as $page) {
         $trail[] = $this->getBreadcrumbItemTag($page)->toString();
     }
     echo implode($spacerTag->toString(), $trail);
     $api->renderChildren($unit);
 }
开发者ID:rukzuk,项目名称:rukzuk,代码行数:35,代码来源:rz_breadcrumb.php

示例2: __invoke

 /**
  * Translate a message.
  *
  * @param  string $message
  * @param  string $textDomain
  * @param  string $locale
  * @return string
  * @throws Exception\RuntimeException
  */
 public function __invoke($message, $textDomain = 'default', $locale = null)
 {
     if ($this->translator === null) {
         return $message;
     }
     return $this->translator->translate($message, $textDomain, $locale);
 }
开发者ID:ahyswang,项目名称:eva-engine,代码行数:16,代码来源:Translate.php

示例3: renderContent

 protected function renderContent($api, $unit, $moduleInfo)
 {
     if ($api->getFormValue($unit, 'imgsrc') != '') {
         if ($api->getFormValue($unit, 'enableImageLink', '') && !$api->isEditMode()) {
             $linkTitle = $api->getFormValue($unit, 'linkTitle');
             $target = "_self";
             if ($api->getFormValue($unit, 'openNewWindow')) {
                 $target = "_blank";
             }
             echo '<a class="imageContainer" href="' . $this->geturl($api, $unit) . '" title="' . $linkTitle . '" target="' . $target . '">';
         } else {
             echo '<div class="imageContainer">';
         }
         echo $this->getResponsiveImageTag($api, $unit, $moduleInfo)->toString();
         if ($api->isEditMode()) {
             $i18n = new Translator($api, $moduleInfo);
             $title = $i18n->translate('button.cropIconTitle');
             echo '<div class="cropIcon" title="' . $title . '"></div>';
         }
         if ($api->getFormValue($unit, 'showCaption', '')) {
             echo '<div class="imageCaption">' . $api->getFormValue($unit, 'imageTitle', '') . '</div>';
         }
         if ($api->getFormValue($unit, 'enableImageLink', '') && !$api->isEditMode()) {
             echo '</a>';
         } else {
             echo '</div>';
         }
     }
     echo $api->getEditableTag($unit, 'text', 'div', 'class="text"');
     $api->renderChildren($unit);
 }
开发者ID:rukzuk,项目名称:rukzuk,代码行数:31,代码来源:rz_text_image.php

示例4: showNoAnchorsHint

 /**
  * @param \Render\APIs\APIv1\RenderAPI  $renderApi
  * @param \Render\Unit                  $unit
  * @param \Render\ModuleInfo            $moduleInfo
  */
 protected function showNoAnchorsHint($renderApi, $unit, $moduleInfo)
 {
     $i18n = new Translator($renderApi, $moduleInfo);
     $msg = $i18n->translate('hint.noAnchor');
     $errorTag = new HtmlTagBuilder('div', array('class' => 'RUKZUKmissingInputHint'), array(new HtmlTagBuilder('button', array('style' => 'cursor: default;'), array($msg))));
     echo $errorTag->toString();
 }
开发者ID:rukzuk,项目名称:rukzuk,代码行数:12,代码来源:rz_anchor_navigation.php

示例5: renderContent

 public function renderContent($renderApi, $unit, $moduleInfo)
 {
     // find all children modules
     $allItems = $renderApi->getChildren($unit);
     $renderItems = array();
     // normal units
     $nonRenderItems = array();
     // extension units
     foreach ($allItems as $item) {
         if ($renderApi->getModuleInfo($item)->isExtension()) {
             // assume that extension modules (i.e. styles) render no html output
             $nonRenderItems[] = $item;
         } else {
             $renderItems[] = $item;
         }
     }
     // wrap all children
     if (empty($renderItems)) {
         if ($renderApi->isEditMode() && $renderApi->isTemplate()) {
             $i18n = new Translator($renderApi, $moduleInfo);
             $msg = $i18n->translate('msg.emptyInEditMode');
             $errorTag = new HtmlTagBuilder('div', array('class' => 'RUKZUKmissingInputHint'), array(new HtmlTagBuilder('button', array('style' => 'cursor: default;'), array($msg))));
             echo $errorTag->toString();
         }
     } else {
         $wrapTag = new HtmlTagBuilder('div');
         foreach ($renderItems as $renderItem) {
             echo $wrapTag->getOpenString();
             $renderApi->renderUnit($renderItem);
             echo $wrapTag->getCloseString();
         }
     }
 }
开发者ID:rukzuk,项目名称:rukzuk,代码行数:33,代码来源:rz_ghost_container.php

示例6: htmlHeadUnit

 public function htmlHeadUnit($api, $unit, $moduleInfo)
 {
     // enable event only if this extension unit is a direct child of default unit
     $parentUnit = $api->getParentUnit($unit);
     if (!$api->getModuleInfo($parentUnit)->isExtension()) {
         $eventType = $api->getFormValue($unit, 'eventType');
         $eventLimit = $api->getFormValue($unit, 'eventLimit');
         $eventMode = $api->getFormValue($unit, 'eventMode');
         $stateName = '';
         if ($api->getFormValue($unit, 'enableState')) {
             $stateName = $api->getFormValue($unit, 'stateName');
         }
         $selector = substr($api->getFormValue($unit, 'additionalSelector'), 2);
         $code = "window.rz_trigger_event.push({ ";
         $code .= "\"selector\": \"" . $selector . "\", \"parentUnitId\": \"" . $parentUnit->getId() . "\", \"eventType\": \"" . $eventType . "\", \"stateName\": \"" . $stateName . "\", \"eventLimit\": \"" . $eventLimit . "\", \"eventMode\": \"" . $eventMode . "\"";
         if ($eventType == 'scroll') {
             $code .= ",\"scrollConfig\": \"" . $api->getFormValue($unit, 'scrollConfig') . "\"";
         }
         $code .= "});";
         return "<script>" . $code . "</script>";
     } else {
         if ($api->isEditMode()) {
             $i18n = new Translator($api, $moduleInfo);
             $msg = $i18n->translate('error.insideExtensionModule');
             $code = 'alert("' . addslashes($msg) . '");';
         }
         return "<script>" . $code . "</script>";
     }
 }
开发者ID:rukzuk,项目名称:rukzuk,代码行数:29,代码来源:rz_trigger_event.php

示例7: renderContent

 protected function renderContent($api, $unit, $moduleInfo)
 {
     echo $this->getResponsiveImageTag($api, $unit, $moduleInfo)->toString();
     if ($api->isEditMode()) {
         $i18n = new Translator($api, $moduleInfo);
         $title = $i18n->translate('button.cropIconTitle');
         echo '<div class="cropIcon" title="' . $title . '"></div>';
     }
     $api->renderChildren($unit);
 }
开发者ID:rukzuk,项目名称:rukzuk,代码行数:10,代码来源:rz_image.php

示例8: renderContent

 /**
  * @param \Render\APIs\APIv1\RenderAPI $renderApi
  * @param \Render\Unit $unit
  * @param \Render\ModuleInfo $moduleInfo
  */
 public function renderContent($renderApi, $unit, $moduleInfo)
 {
     $responsiveImage = new ResponsiveImageBuilder($renderApi, $unit, $moduleInfo);
     $imageIds = $renderApi->getFormValue($unit, 'sliderImageIds', array());
     $imageQuality = null;
     if ($renderApi->getFormValue($unit, 'enableImageQuality')) {
         $imageQuality = $renderApi->getFormValue($unit, 'imageQuality');
     }
     $globalHeightPercent = str_replace('%', '', $renderApi->getFormValue($unit, 'imgHeight'));
     // render children (non extensions)
     if (count($imageIds) > 0) {
         echo '<ul class="slides">';
         $i = 0;
         foreach ($imageIds as $imageId) {
             // image
             try {
                 $image = $renderApi->getMediaItem($imageId)->getImage();
                 if ($globalHeightPercent == 0) {
                     $heightPercent = $image->getHeight() / $image->getWidth() * 100;
                 } else {
                     $heightPercent = $globalHeightPercent;
                 }
                 $cropHeight = $image->getWidth() * $heightPercent / 100;
                 // slides
                 if ($i == 0) {
                     echo '<li class="slide slideActive">';
                 } else {
                     echo '<li class="slide">';
                 }
                 $i++;
                 // image tag
                 $imgTag = $responsiveImage->getImageTag($image, array('resize' => array('width' => $image->getWidth(), 'height' => $cropHeight), 'quality' => $imageQuality));
                 if (isset($imgTag)) {
                     echo $imgTag->toString();
                 }
                 echo '</li>';
             } catch (\Exception $e) {
             }
         }
         echo '</ul>';
     } else {
         if ($renderApi->isEditMode()) {
             // missing input hint
             $i18n = new Translator($renderApi, $moduleInfo);
             echo '<div class="RUKZUKmissingInputHint">';
             echo '<div>';
             echo '<button onclick="javascript:CMS.openFormPanel(\'sliderImageIds\');">';
             echo $i18n->translate('button.missingInputHint', 'Choose images');
             echo '</button>';
             echo '</div>';
             echo '</div>';
         }
     }
     $renderApi->renderChildren($unit);
 }
开发者ID:rukzuk,项目名称:rukzuk,代码行数:60,代码来源:rz_slider_images.php

示例9: testTranslateMissingKey

 public function testTranslateMissingKey()
 {
     $formatter = $this->getMock(get_class($this->formatter));
     // create fallback translator
     $translator = new Translator('en_US', [], $formatter);
     $formatter->expects($this->once())->method('format')->with('en_US', 'TEXT', ['var' => 'SOME'])->will($this->returnValue('FORMATTED'));
     // key does not exist, with tokens passed
     $expect = 'FORMATTED';
     $actual = $translator->translate('TEXT', ['var' => 'SOME']);
     $this->assertEquals($expect, $actual);
 }
开发者ID:Slayug,项目名称:castor,代码行数:11,代码来源:TranslatorTest.php

示例10: htmlHeadUnit

 public function htmlHeadUnit($api, $unit, $moduleInfo)
 {
     // enable event only if this extension unit is a direct child of default unit
     $parentUnit = $api->getParentUnit($unit);
     if ($api->getModuleInfo($parentUnit)->isExtension()) {
         if ($api->isEditMode()) {
             $i18n = new Translator($api, $moduleInfo);
             $msg = $i18n->translate('error.insideExtensionModule');
             $code = 'alert("' . addslashes($msg) . '");';
         }
         return "<script>" . $code . "</script>";
     }
 }
开发者ID:rukzuk,项目名称:rukzuk,代码行数:13,代码来源:rz_style_styleset.php

示例11: renderContent

 /**
  * @param \Render\APIs\APIv1\RenderAPI $renderApi
  * @param \Render\Unit                 $unit
  * @param \Render\ModuleInfo           $moduleInfo
  */
 public function renderContent($renderApi, $unit, $moduleInfo)
 {
     $imageIds = $this->getImageIds($renderApi, $unit);
     $imageQuality = null;
     if ($renderApi->getFormValue($unit, 'enableImageQuality')) {
         $imageQuality = $renderApi->getFormValue($unit, 'imageQuality');
     }
     $globalHeightPercent = str_replace('%', '', $renderApi->getFormValue($unit, 'imgHeight'));
     // render images
     if (count($imageIds) > 0) {
         echo '<ul>';
         foreach ($imageIds as $imageId) {
             try {
                 // image
                 $image = $renderApi->getMediaItem($imageId)->getImage();
                 if ($globalHeightPercent == 0) {
                     $heightPercent = $image->getHeight() / $image->getWidth() * 100;
                 } else {
                     $heightPercent = $globalHeightPercent;
                 }
                 $cropHeight = $image->getWidth() * $heightPercent / 100;
                 if ($renderApi->getFormValue($unit, 'showImageTitles')) {
                     $name = $renderApi->getMediaItem($imageId)->getName();
                     $attributes = array('title' => $name);
                 } else {
                     $attributes = null;
                 }
                 // image tag
                 $imgTag = $this->getResponsiveImage($renderApi, $unit, $moduleInfo)->getImageTag($image, array('resize' => array('width' => $image->getWidth(), 'height' => $cropHeight), 'quality' => $imageQuality), $attributes);
                 echo '<li>' . $imgTag->toString() . '</li>';
             } catch (\Exception $doNothing) {
             }
         }
         echo '</ul>';
     } else {
         if ($renderApi->isEditMode()) {
             // missing input hint
             $i18n = new Translator($renderApi, $moduleInfo);
             echo '<div class="RUKZUKmissingInputHint">';
             echo '<div>';
             echo '<button onclick="javascript:CMS.openFormPanel(\'galleryImageIds\');">';
             echo $i18n->translate('button.missingInputHint', 'Choose images');
             echo '</button>';
             echo '</div>';
             echo '</div>';
         }
     }
     $renderApi->renderChildren($unit);
 }
开发者ID:rukzuk,项目名称:rukzuk,代码行数:54,代码来源:rz_thumbnail_gallery.php

示例12: htmlHeadUnit

 /**
  * @param \Render\APIs\APIv1\CSSAPI $api
  * @param \Render\Unit $unit
  * @param \Render\ModuleInfo $moduleInfo
  * @return string
  */
 protected function htmlHeadUnit($api, $unit, $moduleInfo)
 {
     $parentUnit = $api->getParentUnit($unit);
     // enable animation only if this extension unit is a direct child of default unit
     if (!$api->getModuleInfo($parentUnit)->isExtension()) {
         $selector = '#' . $parentUnit->getId();
         return "<script>window.rz_style_animation_scroll.push('" . $selector . "');</script>";
     } else {
         if ($api->isEditMode()) {
             $i18n = new Translator($api, $moduleInfo);
             $msg = $i18n->translate('error.insideExtensionModule');
             return '<script>alert("' . addslashes($msg) . '");</script>';
         }
     }
 }
开发者ID:rukzuk,项目名称:rukzuk,代码行数:21,代码来源:rz_style_animation_scroll.php

示例13: renderContent

 public function renderContent($renderApi, $unit, $moduleInfo)
 {
     $listTag = new HtmlTagBuilder('ul', array('class' => 'isTeaserList'));
     echo $listTag->getOpenString();
     // show hint when no children inserted
     if ($renderApi->isEditMode() && count($renderApi->getChildren($unit)) === 0) {
         $i18n = new Translator($renderApi, $moduleInfo);
         $msg = $i18n->translate('error.pleaseInsertModules');
         $errorTag = new HtmlTagBuilder('div', array('class' => 'RUKZUKmissingInputHint'), array(new HtmlTagBuilder('button', array('style' => 'cursor: default;'), array($msg))));
         echo $errorTag->toString();
     } else {
         $this->renderTeaserList($renderApi, $unit);
     }
     echo $listTag->getCloseString();
 }
开发者ID:rukzuk,项目名称:rukzuk,代码行数:15,代码来源:rz_page_list.php

示例14: translateInYandex

function translateInYandex($sentence)
{
    $apiKey = '<paste your API key here>';
    $translatedSentence = "";
    try {
        $translator = new Translator($apiKey);
        $translatedSentence = $translator->translate($sentence, 'en-ru');
        //echo $translation; // Привет мир
        //echo $translation->getSource(); // Hello world;
        //echo $translation->getSourceLanguage(); // en
        //echo $translation->getResultLanguage(); // ru
    } catch (Exception $e) {
        // handle exception
    }
    return $translatedSentence;
}
开发者ID:pwrmind,项目名称:TranslatorToolkit,代码行数:16,代码来源:translator.php

示例15: translateFN

/**
 * function translateFN: used to handle message translations
 * based on user language
 *
 * @param string $message - the message to be translated
 * @param string $language_from
 * @param string $language_to 2 char string
 * @return string the translated message, if a translation was found, the original message otherwise
 */
function translateFN($message, $language_from = null, $language_to = null)
{
    if (is_null($language_to)) {
        $sess_userObj = $_SESSION['sess_userObj'];
        $languageId = $sess_userObj->getLanguage();
    } else {
        $languageId = $language_to;
    }
    if ($languageId != 0) {
        $languageInfo = Translator::getLanguageInfoForLanguageId($languageId);
        $user_language_code = $languageInfo['codice_lingua'];
    } else {
        if (!isset($_SESSION['sess_user_language'])) {
            $user_language_code = ADA_LOGIN_PAGE_DEFAULT_LANGUAGE;
        } else {
            $user_language_code = $_SESSION['sess_user_language'];
        }
    }
    return Translator::translate($message, $user_language_code);
}
开发者ID:eguicciardi,项目名称:ada,代码行数:29,代码来源:output_funcs.inc.php


注:本文中的Translator::translate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。