本文整理汇总了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);
}
示例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>";
}
}
示例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();
}
}
}
示例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);
}
示例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();
}
示例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());
}
示例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));
}
}
示例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];
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
}
示例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>";
}
}
示例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);
}
示例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();
}