當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Translator類代碼示例

本文整理匯總了PHP中Translator的典型用法代碼示例。如果您正苦於以下問題:PHP Translator類的具體用法?PHP Translator怎麽用?PHP Translator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Translator類的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: testSerialize

 public function testSerialize()
 {
     $test = array('en' => 'english', 'fr' => 'french');
     $translator = new Translator();
     $translator->processInput($test);
     // test if json serialization is correct
     $this->assertJsonStringEqualsJsonString(json_encode($test), $translator->serialize());
 }
開發者ID:aozisik,項目名稱:translatable,代碼行數:8,代碼來源:TranslatorTest.php

示例7: testTranslateAlphabet

 /**
  * @dataProvider providerTestTranslateAlphabet
  */
 public function testTranslateAlphabet($expected, $letters)
 {
     $translator = new Translator(new Impulsions\DotAndDash());
     $separedtedLetters = preg_split('~~u', $letters, -1, PREG_SPLIT_NO_EMPTY);
     foreach ($separedtedLetters as $letter) {
         $this->assertSame($expected, $translator->morsify($letter));
     }
 }
開發者ID:lebris,項目名稱:morse,代碼行數:11,代碼來源:TranslatorTest.php

示例8: getTranslatorToLocale

 static function getTranslatorToLocale($str = "us")
 {
     if (!isset(self::$trl[$str])) {
         $cfg = self::getConfig();
         $trl = new Translator($cfg);
         $trl->setLanguage($str);
         self::$trl[$str] = $trl;
     }
     return self::$trl[str];
 }
開發者ID:KingsleyGU,項目名稱:OSTicket-Reloaded,代碼行數:10,代碼來源:class.sys.php

示例9: 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

示例10: 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

示例11: 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

示例12: run

 public function run()
 {
     $this->input = filter_input(INPUT_POST, 'english', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
     if (isset($this->input)) {
         $lexer = new Lexer($this->input);
         $tokens = $lexer->run();
         $translator = new Translator($tokens);
         $result = $translator->run();
         if ($this->isAjax()) {
             $this->sendPayload($result);
         }
     }
 }
開發者ID:martinsifra,項目名稱:PigLatin,代碼行數:13,代碼來源:Driver.php

示例13: 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

示例14: 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

示例15: 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


注:本文中的Translator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。