當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。