예제 #1
0
 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
0
 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
0
 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
0
 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
0
 /**
  * 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);
 }
예제 #6
0
 /**
  * @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();
 }
예제 #7
0
 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());
 }
예제 #8
0
 /**
  * @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));
     }
 }
 /**
  * @param JsonSerializationVisitor $visitor
  * @param Narrative                $narrative
  * @param array                    $type
  * @param Context                  $context
  * @return array
  */
 public function translateNarrative(JsonSerializationVisitor $visitor, Narrative $narrative, array $type, Context $context)
 {
     $messageData = $narrative->getMessages();
     foreach ($messageData as $key => &$messages) {
         foreach ($messages as &$message) {
             $message = $this->translationService->trans($message, $narrative->getSubstitutions(), $key, 'en');
         }
     }
     return $messageData;
 }
예제 #10
0
 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];
 }
예제 #11
0
파일: rz_image.php 프로젝트: rukzuk/rukzuk
 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);
 }
예제 #12
0
 public function __invoke($dataType, $dataKey, $locale = null)
 {
     if (!$locale) {
         $locale = $this->translator->getLocale();
     }
     $list = Data::getList($locale, $dataType);
     if (isset($list[$dataKey])) {
         return $list[$dataKey];
     }
 }
예제 #13
0
 /**
  * @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);
 }
예제 #14
0
파일: Country.php 프로젝트: znck/countries
 /**
  * @param string $val
  *
  * @return string
  */
 public function getNameAttribute(string $val)
 {
     if (static::$locale === 'en') {
         return $val;
     }
     $name = static::$countries->getName($this->code, static::$locale);
     if ($name === $this->code) {
         return $val;
     }
     return $name;
 }
예제 #15
0
 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);
 }
예제 #16
0
 /**
  * Adds an action to the list of available .
  *
  * @param string $key    - a unique identifier; it is recommended that it be namespaced i.e. lead.action
  * @param array  $action - can contain the following keys:
  *  'label'           => (required) what to display in the list
  *  'description'     => (optional) short description of event
  *  'template'        => (optional) template to use for the action's HTML in the stage builder
  *      i.e AcmeMyBundle:StageAction:theaction.html.php
  *  'formType'        => (optional) name of the form type SERVICE for the action; will use a default form with stage change only
  *  'formTypeOptions' => (optional) array of options to pass to formType
  *  'callback'        => (optional) callback function that will be passed when the action is triggered; return true to
  *                       change the configured stages or false to ignore the action
  *      The callback function can receive the following arguments by name (via ReflectionMethod::invokeArgs())
  *          Mautic\CoreBundle\Factory\MauticFactory $factory
  *          Mautic\LeadBundle\Entity\Lead $lead
  *          $eventDetails - variable sent from firing function to call back function
  *          array $action = array(
  *              'id' => int
  *              'type' => string
  *              'name' => string
  *              'properties' => array()
  *         )
  *
  * @return void
  * @throws InvalidArgumentException
  */
 public function addAction($key, array $action)
 {
     if (array_key_exists($key, $this->actions)) {
         throw new InvalidArgumentException("The key, '{$key}' is already used by another action. Please use a different key.");
     }
     //check for required keys and that given functions are callable
     $this->verifyComponent(array('group', 'label'), array('callback'), $action);
     //translate the label and group
     $action['label'] = $this->translator->trans($action['label']);
     $action['group'] = $this->translator->trans($action['group']);
     $this->actions[$key] = $action;
 }
예제 #17
0
 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);
         }
     }
 }
예제 #18
0
 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>";
     }
 }
예제 #19
0
 /**
  * @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);
 }
예제 #20
0
 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();
 }
예제 #21
0
 /**
  * @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>';
         }
     }
 }
예제 #22
0
 public static function getInstance()
 {
     if (is_null(self::$instance)) {
         self::$instance = new Translator();
     }
     return self::$instance;
 }
예제 #23
0
 /**
  * Clean up a languages dir
  *
  * @param string $dir Languages dir
  *
  * @return void
  */
 public function cleanLanguagesDir($dir)
 {
     $dir = rtrim($dir, '/\\');
     foreach (scandir($dir) as $entry) {
         if ($entry[0] === '.') {
             continue;
         }
         if (pathinfo($entry, PATHINFO_EXTENSION) !== 'php') {
             continue;
         }
         $path = "{$dir}/{$entry}";
         $code = basename($entry, '.php');
         if (!in_array($code, $this->codes)) {
             $code = Translator::normalizeLanguageCode($code);
             if (in_array($code, $this->codes)) {
                 // rename file to lowercase
                 rename($path, "{$dir}/{$code}.php");
                 $this->log[] = "Renamed {$path} to {$code}.php";
                 continue;
             }
             unlink($path);
             $this->log[] = "Removed {$path}";
         }
     }
 }
예제 #24
0
    public static function getOne($id)
    {
        $data = array();
        $sql = '
			SELECT * FROM {{translator}}
			WHERE id=' . $id . '
		';
        $item = DB::getRow($sql);
        $sql = '
			SELECT * FROM {{translator}}
			WHERE parent=' . $item['id'] . '
		';
        $rows = DB::getALL($sql);
        foreach (Translator::getLanguage() as $ii => $lang) {
            if ($ii == 0) {
                $data[$item['lang']] = $item;
            } else {
                foreach ($rows as $row) {
                    if ($row['lang'] == $lang['value']) {
                        $data[$row['lang']] = $row;
                    }
                }
            }
        }
        return $data;
    }
예제 #25
0
 /**
  * Get Translator
  *
  * Provides access to the Translator singleton
  *
  * @return Translator The translator object
  */
 public static function getTranslator()
 {
     if (self::$instance == null) {
         self::$instance = new Translator();
     }
     return self::$instance;
 }
예제 #26
0
 /**
  * Constructor
  * @param string     gallery id
  * @param sgGallery  reference to the parent gallery
  */
 function sgGallery($id, &$parent)
 {
     $this->id = $id;
     $this->parent = $parent;
     $this->config = sgConfig::getInstance();
     $this->translator = Translator::getInstance();
 }
예제 #27
0
파일: BaseForm.php 프로젝트: gerq/gpstuner
 public function __construct()
 {
     $this->_view = View::getInstance();
     $this->_request = Request::getInstance();
     $this->_validator = Validator::getInstance();
     $this->_translator = Translator::getInstance();
 }
예제 #28
0
    public function getFormHtml()
    {
        ?>
			<fieldset>
				<legend><?php 
        echo Translator::get('module_config');
        ?>
</legend>
				<div class="form-fields">
					<?php 
        $this->addInputText('config[charset]', Translator::get('module_default_charset'), $this->config->get('charset'))->addInputText('config[language]', Translator::get('module_default_language'), $this->config->get('language'))->addInputText('config[locale]', Translator::get('module_default_locale'), $this->config->get('locale'))->addInputText('config[module]', Translator::get('module_default_module'), $this->config->get('module'))->addInputText('config[action]', Translator::get('module_default_action'), $this->config->get('action'));
        ?>
				</div>
			</fieldset>
			<?php 
        foreach ($this->envs as $env) {
            ?>
			<fieldset>
				<legend><?php 
            echo Translator::get('module_config_' . $env);
            ?>
</legend>
				<div class="form-fields">
					<?php 
            $this->addInputText('config[' . $env . '][http_host]', Translator::get('module_http_host'), $this->config->getEnvKey($env, 'http_host'))->addInputText('config[' . $env . '][contact]', Translator::get('module_contact'), $this->config->getEnvKey($env, 'contact'))->addInputText('config[' . $env . '][host]', Translator::get('module_database_host'), $this->config->getEnvKey($env, 'host'))->addInputText('config[' . $env . '][database]', Translator::get('module_database_database'), $this->config->getEnvKey($env, 'database'))->addInputText('config[' . $env . '][user]', Translator::get('module_database_user'), $this->config->getEnvKey($env, 'user'))->addInputText('config[' . $env . '][password]', Translator::get('module_database_password'), $this->config->getEnvKey($env, 'password'));
            ?>
				</div>
			</fieldset>
			<?php 
        }
        ?>
		<?php 
    }
예제 #29
0
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;
}
예제 #30
0
 /**
  * @return XPathExpr
  */
 public function addNameTest()
 {
     if ('*' !== $this->element) {
         $this->addCondition('name() = ' . Translator::getXpathLiteral($this->element));
         $this->element = '*';
     }
     return $this;
 }