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); }
/** * 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); }
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); }
/** * @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(); }
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(); } } }
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>"; } }
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); }
/** * @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); }
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); }
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>"; } }
/** * @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); }
/** * @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>'; } } }
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(); }
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; }
/** * 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); }
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() || $api->getModuleInfo($parentUnit)->getId() == "rz_styleset") { if ($api->isEditMode()) { $i18n = new Translator($api, $moduleInfo); $msg = $i18n->translate('error.insideExtensionModule'); $code = 'alert("' . addslashes($msg) . '");'; } } else { $parentUnitId = $parentUnit->getId(); $mp4 = $api->getFormValue($unit, 'cssMp4'); if ($mp4 != '') { $mp4Url = $api->getMediaItem($api->getFormValue($unit, 'cssMp4'))->getUrl(); $mute = $api->getFormValue($unit, 'cssMute'); $loop = $api->getFormValue($unit, 'cssLoop'); $playbackRate = $api->getFormValue($unit, 'cssSpeed'); $code = "\$(function() { \$('#" . $parentUnitId . "').vide({mp4:'" . $mp4Url . "'},{playbackRate:" . $playbackRate . ",muted:" . $mute . ",loop:" . $loop . "}); });"; } } return "<script>" . $code . "</script>"; }
public function getTextTag($renderApi, $unit, $moduleInfo, $content, $url) { $charLimit = $renderApi->getFormValue($unit, 'textCharLimit'); if (empty($content) && $renderApi->isEditMode()) { $i18n = new Translator($renderApi, $moduleInfo); $description = $i18n->translate('placeholder.pageDescription'); $content = $description . ' - Lorem ipsum dolor sit amet, eos ea soleat causae. Pro elitr eleifend prodesset ad, etiam volutpat no per, vim ea consul denique. Ullum lobortis evertitur ne vim, has audire incorrupte theophrastus at. Labitur vivendum electram pro et, sed movet accusata gloriatur at. Amet oratio repudiandae cu vis.'; } if ($charLimit > 0) { $content = $this->trimText($content, $charLimit); } // add space if link will get appended if ($renderApi->getFormValue($unit, 'enableTextLink')) { $content .= ' '; } $return = new HtmlTagBuilder('p', array('class' => 'teaserText'), array($content)); if ($renderApi->getFormValue($unit, 'enableTextLink')) { $return->append(new HtmlTagBuilder('a', array('href' => $url, 'class' => 'teaserTextLink'), array($renderApi->getFormValue($unit, 'textLinkLabel')))); } return $return; }
/** * @param array $matches * * @return string */ private function callback(array $matches) { $subresult = preg_replace('/^[^\\[]+\\[([^\\]]*)\\].*$/', '$1', $this->translator->translate($matches[2])); return $matches[1] . '[not(' . $subresult . ')]'; }
/** * this is the main feature of the view, in the MVC paradigm the controller sends updates to the view, this is * the method which captures the updates. * * The uri is essentially the part of the system which we are updating so different output will be negotiated * depending on the value of the uri. * * The data are the things which have changed due to the controller. * * The message is optional, it is for notes, debug information or with json sending messages back alongside the data * * @param string $uri * @param array $data * @return void * @author Craig Ulliott */ public static function update($uri, $data = NULL) { // extract the base from the url, we use this to determine the type of output $uri_r = explode('/', trim($uri, '/'), 2); $base = array_val($uri_r, 0); $path = array_val($uri_r, 1); // for an error we try and determine the best format to send back the message if ($base == 'error') { // if the original request came from AJAX if (array_val($_SERVER, 'HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest') { // rewrite and use the json handler for this error $base = 'json'; $path = 'fail'; $data = array_val($data, 'message', 'Unknown Error'); } else { // pass back the appropriate http code for this error $code = array_val($data, 'code'); switch ($code) { case '404': header("HTTP/1.0 404 Not Found"); break; case '500': header("HTTP/1.0 500 Internal Server Error"); break; default: die('unknown error code "' . $code . '"'); } // use the page handler to display this error $base = 'page'; $path = 'error/' . $code; } } // for an error, we try to determine if we are // we handle the update differently depending on the base of the uri switch ($base) { // these are the different layout files, we are loading a whole page template and passing the result into these layouts case 'page': // we are preparing a full html page $tpl_vars = array(); // the part of the page being updated from teh controller (aka the page contents) $tpl_vars['page_content'] = Template::loadTemplate($path, $data); // script and css clien side includes $tpl_vars['css_url'] = ENV == 'dev' ? '/css/generate' : STATIC_BASE_URL . 'css/style.css'; $tpl_vars['js_url'] = ENV == 'dev' ? '/js/generate' : STATIC_BASE_URL . 'js/script.js'; // todo:: $tpl_vars['css_url'] = '/css/generate'; $tpl_vars['js_url'] = '/js/generate'; // the facebook API key $tpl_vars['fb_api_key'] = getConfiguration('facebook', 'api_key'); // user values $tpl_vars['current_uid'] = CURRENT_UID; $tpl_vars['current_session_key'] = CURRENT_SESSION_KEY; // the parts of the path $path_r = explode('/', $path); // the active section is the first part of the path $active_section = reset($path_r); // used to set an active class on the main tab $tpl_vars['active'] = $active_section; // we build body classes to target css more accurately, one whole class for each parent section $body_classes = array(); while ($path_r) { $body_classes[] = implode('-', $path_r); array_pop($path_r); } // the current login state if (CURRENT_UID) { $body_classes[] = 'logged-in'; } // the current browser (TODO:) if (true == false) { $body_classes[] = 'ie-7'; } // the body classes, used to determine the browser and login state $tpl_vars['body_class'] = implode(' ', $body_classes); // render the full page in either the base or admin layout file $output = Template::loadLayout($base, $tpl_vars); // complete the translations Translator::translate('en'); $output = Translator::parse($output); // useful headers for debugging self::outputDebugHeaders(); // output to the browser die($output); // partial means we are rendering a template (usualy html) but not passing it back into the page template // this is usually for partial page updates preformed by javascript // partial means we are rendering a template (usualy html) but not passing it back into the page template // this is usually for partial page updates preformed by javascript case 'partial': // render the template and output to the browser $output = Template::loadTemplate($path, $data); // complete the translations Translator::translate('en'); $translated_output = Translator::parse($output); // useful headers for debugging self::outputDebugHeaders(); // to hold the output $r = array(); // the rest of the params go into the data key $r['page'] = $translated_output; // the correct content type header('Content-type: application/json'); // build and send the json back to the browser $encoded_output = json_encode($r); die($encoded_output); // json is used by javascript for various AJAX functionality // json is used by javascript for various AJAX functionality case 'json': $r = array(); switch ($path) { // ouput raw json data case 'data': // the content type header('Content-type: application/json'); // build and send the json back to the browser $encoded_output = json_encode($data); die($encoded_output); // success means we simply set the success key to 1, javascript will capture this // success means we simply set the success key to 1, javascript will capture this case 'success': $r['success'] = 1; break; // fail means we simply set the success key to 0, javascript will capture this and handle is as a fail // fail means we simply set the success key to 0, javascript will capture this and handle is as a fail case 'fail': $r['success'] = 0; break; default: throw new exception($path . ' is not a valid path for json output'); } // the data variable is used for sending back a message // it is sent as a blank string if one wasnt provided $r['message'] = (string) $data; // the correct content type header('Content-type: application/json'); // build and send the json back to the browser $encoded_output = json_encode($r); die($encoded_output); // content pass through, with the uri as a content type // content pass through, with the uri as a content type case 'content': // the different content types we accept switch ($path) { // common image types case 'image/png': case 'image/gif': case 'image/jpeg': // css and js // css and js case 'text/css': case 'text/javascript': case 'text/html': // data // data case 'text/csv': // the content type header('Content-type: ' . $path); // other useful headers for debugging self::outputDebugHeaders(); // send to the browser die($data); default: throw new exception($path . ' is not a known safe content type'); } default: throw new exception($base . ' is not a valid base for updating this view'); } }
<?php // Class autoloader spl_autoload_register(function ($className) { $filePath = 'src' . DIRECTORY_SEPARATOR . $className . '.php'; if (file_exists($filePath)) { require_once $filePath; } else { require_once 'src' . DIRECTORY_SEPARATOR . 'Material' . DIRECTORY_SEPARATOR . $className . '.php'; } if (file_exists('vendor/autoload.php')) { require_once 'vendor/autoload.php'; } }); // Instantiate a translator $translator = new Translator(); try { $translator->translate(new Book('fr')); $translator->translate(new Magazine()); $translator->translate(new Audiobook()); $translator->translate(new Movie('de')); } catch (\Exception $e) { echo $e->getMessage() . PHP_EOL; // why this shit doesn't work? }
?> </li> <li> 5 - <?php Translator::translate('remove_maintenance_mode'); ?> </li> </ul> </div> <a id="start-btn" class="btn btn-primary" data-toggle="modal" data-target="#upgrade-modal"> <?php Translator::translate('start'); ?> </a> <a id="return-btn" href=".." class="btn btn-danger"> <?php Translator::translate('return'); ?> </a> </div> </div> </div> </div> </div> <!----------------------- MODAL --------------------------------> <div class="modal fade" id="upgrade-modal"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header">
/** * Returns the full answer for the question that matches $fieldName * and the answer that matches the $answerCode. If a match cannot * be made then false is returned. * * The name of the variable $answerCode is not strictly an answerCode * but could also be a comment entered by a participant. * * @param string $fieldName * @param string $answerCode * @param Translator $translator * @param string $sLanguageCode * @return string (or false) */ public function getFullAnswer($fieldName, $answerCode, Translator $translator, $sLanguageCode) { $fullAnswer = null; $fieldType = $this->fieldMap[$fieldName]['type']; $question = $this->fieldMap[$fieldName]; $questionId = $question['qid']; $answer = null; if ($questionId) { $answers = $this->getAnswers($questionId); if (isset($answers[$answerCode])) { $answer = $answers[$answerCode]['answer']; } } //echo "\n$fieldName: $fieldType = $answerCode"; switch ($fieldType) { case 'R': //RANKING TYPE $fullAnswer = $answer; break; case '1': //Array dual scale if (mb_substr($fieldName, -1) == 0) { $answers = $this->getAnswers($questionId, 0); } else { $answers = $this->getAnswers($questionId, 1); } if (array_key_exists($answerCode, $answers)) { $fullAnswer = $answers[$answerCode]['answer']; } else { $fullAnswer = null; } break; case 'L': //DROPDOWN LIST //DROPDOWN LIST case '!': if (mb_substr($fieldName, -5, 5) == 'other') { $fullAnswer = $answerCode; } else { if ($answerCode == '-oth-') { $fullAnswer = $translator->translate('Other', $sLanguageCode); } else { $fullAnswer = $answer; } } break; case 'O': //DROPDOWN LIST WITH COMMENT if (isset($answer)) { //This is one of the dropdown list options. $fullAnswer = $answer; } else { //This is a comment. $fullAnswer = $answerCode; } break; case 'Y': //YES/NO switch ($answerCode) { case 'Y': $fullAnswer = $translator->translate('Yes', $sLanguageCode); break; case 'N': $fullAnswer = $translator->translate('No', $sLanguageCode); break; default: $fullAnswer = $translator->translate('N/A', $sLanguageCode); } break; case 'G': switch ($answerCode) { case 'M': $fullAnswer = $translator->translate('Male', $sLanguageCode); break; case 'F': $fullAnswer = $translator->translate('Female', $sLanguageCode); break; default: $fullAnswer = $translator->translate('N/A', $sLanguageCode); } break; case 'M': //MULTIOPTION //MULTIOPTION case 'P': if (mb_substr($fieldName, -5, 5) == 'other' || mb_substr($fieldName, -7, 7) == 'comment') { //echo "\n -- Branch 1 --"; $fullAnswer = $answerCode; } else { switch ($answerCode) { case 'Y': $fullAnswer = $translator->translate('Yes', $sLanguageCode); break; case 'N': case '': $fullAnswer = $translator->translate('No', $sLanguageCode); break; default: //echo "\n -- Branch 2 --"; $fullAnswer = $answerCode; } } break; case 'C': switch ($answerCode) { case 'Y': $fullAnswer = $translator->translate('Yes', $sLanguageCode); break; case 'N': $fullAnswer = $translator->translate('No', $sLanguageCode); break; case 'U': $fullAnswer = $translator->translate('Uncertain', $sLanguageCode); break; } break; case 'E': switch ($answerCode) { case 'I': $fullAnswer = $translator->translate('Increase', $sLanguageCode); break; case 'S': $fullAnswer = $translator->translate('Same', $sLanguageCode); break; case 'D': $fullAnswer = $translator->translate('Decrease', $sLanguageCode); break; } break; case 'F': case 'H': $answers = $this->getAnswers($questionId, 0); $fullAnswer = isset($answers[$answerCode]) ? $answers[$answerCode]['answer'] : ""; break; default: $fullAnswer .= $answerCode; } return $fullAnswer; }
</article> </section> <img id="logo" src="images/logo.png" alt="Logo Conversor subtítulos latinos" /> </div> </div> <div id="bottomPart" > <?php $viewFactory = new ViewFactory(); if (isset($_GET['editar']) == true) { if ($_SESSION['security_code'] != $_POST['captchaUser']) { $viewFactory->showError("Código verificador inválido", "convertir-subtitulo", "images/btnBack.png"); } else { $_SESSION['security_code'] = "0"; $viewFactory->showEditTitles(); $translator = new Translator(); $translatedLines = $translator->translate(); if ($translator->isOK()) { if ($viewFactory->buildEditForm("conversor.php", $_FILES['file']['name'], $translatedLines, "convertir-subtitulo", "images/btnBack.png") == false) { $viewFactory->showError("El archivo no necesita traducción", "convertir-subtitulo", "images/btnBack.png"); } } else { $viewFactory->showError($translator->getError(), "convertir-subtitulo", "images/btnBack.png"); } } } else { $viewFactory->buildUploadForm("editar-conversion"); } ?> </div>
/** * @covers MarkupTranslator\Translator::translate */ public function testTranslate() { $testCase = 'test'; $this->assertEquals($testCase, Translator::translate($testCase, 'github', 'github')); }
$page['lang-root'] = $sitewide['root']; if (isset($page['lang']) && $page['lang'] != 'en') { $page['lang-root'] .= $page['lang'] . '/'; } if (!isset($page['path'])) { $page['path'] = str_replace($sitewide['root'], '/', $sitewide['path']); $page['path'] = str_replace('/' . $page['lang'] . '/', '/', $page['path']); } if (!isset($page['name'])) { $page['name'] = trim(preg_replace('#\\.php$#', '', $page['path']), '/'); if (empty($page['name'])) { $page['name'] = 'index'; } } if (isset($page['title'])) { $page['title'] = $l10n->translate($page['title'], $page['name']); } $l10n->init(); $l10n->set_domain('layout'); $l10n->begin_html_translation(); ?> <!doctype html> <!--[if IE 9]><html lang="<?php echo !empty($page['lang']) ? $page['lang'] : 'en'; ?> " class="ie9"><![endif]--> <!--[if (gt IE 9)|!(IE)]><!--><html lang="<?php echo !empty($page['lang']) ? $page['lang'] : 'en'; ?> "><!--<![endif]--> <head>
/** * @param array $fields * @param array $data * @param array $errors */ protected function validateFields($fields, $data, &$errors) { foreach ($fields as $fieldName => $field) { if ($field instanceof PlainField) { foreach ($field->getConstraints() as $constraint) { if (!$constraint->validate($this->getVar($fieldName, $data))) { if (!isset($errors[$fieldName])) { $errors[$fieldName] = array(); } $errors[$fieldName][] = $this->translator->translate($constraint->getErrorMessage($field->getName(), $field->getDescription())); } } } elseif ($field instanceof ArrayField) { $items = $this->getVar($fieldName, $data); if ($items === null && $field->isOptional()) { continue; } if (!isset($errors[$fieldName])) { $errors[$fieldName] = array(); } if (!is_array($items)) { $errors[$fieldName][] = sprintf('%s is not an array', $field->getDescription()); continue; } if (!empty($items) && !is_array(reset($items))) { $errors[$fieldName][] = sprintf('Invalid array item in %s', $field->getDescription()); continue; } foreach ($items as $index => $item) { $err = array(); $this->validateFields($field->getItemFields()->getFields(), $item, $err); if ($err) { $errors[$fieldName]['item_' . $index] = $err; } } if (count($errors[$fieldName]) === 0) { unset($errors[$fieldName]); } } elseif ($field instanceof CompoundField) { $keyValues = $this->getVar($fieldName, $data); if ($keyValues === null && $field->isOptional()) { continue; } if (!isset($errors[$fieldName])) { $errors[$fieldName] = array(); } if (!is_array($keyValues)) { $errors[$fieldName][] = sprintf('%s is not an array', $field->getDescription()); continue; } $err = array(); $this->validateFields($field->getFields(), $keyValues, $err); if ($err) { $errors[$fieldName] = $err; } if (count($errors[$fieldName]) === 0) { unset($errors[$fieldName]); } $constraints = $field->getConstraints(); foreach ($constraints as $constraint) { $fieldNames = $constraint->getFields(); $keyValues = $this->getVars($fieldNames, $keyValues); $isValid = $constraint->validate($keyValues); if (!$isValid) { if (!isset($errors[$fieldName])) { $errors[$fieldName][$constraint->getTargetField()] = array(); } if (!isset($errors[$fieldName][$constraint->getTargetField()])) { $errors[$fieldName][$constraint->getTargetField()] = array(); } $errors[$fieldName][$constraint->getTargetField()][] = $this->translator->translate($constraint->getErrorMessage()); } } } } }
/** * @covers phpDocumentor\Translator\Translator::addTranslationFolder * @covers phpDocumentor\Translator\Translator::translate */ public function testCanUseTranslationsFromASpecificDomainOrCatalogue() { $this->fixture->addTranslationsUsingPattern(dirname($this->domainFilename), 'domain'); $this->assertEquals('domain', $this->fixture->translate(self::TEST_KEY, 'domain')); }
/** * @covers phpDocumentor\Translator::addTranslationFolder * @covers phpDocumentor\Translator::translate */ public function testCanUseTranslationFromFolder() { $this->fixture->addTranslationFolder(dirname($this->filename)); $this->assertEquals(self::TEST_VALUE, $this->fixture->translate(self::TEST_KEY)); }
<div id="challenges_canvas"> <div id="description"></div> <div id="form"> <form action="<?php echo $PHP_SELF; ?> " method="post" accept-charset="utf-8"> <p>English written number</p> <input type="text" size="80" name="string" value="<?php echo $_POST['string']; ?> "/><input type="submit" value="Translate" /> </form> <div id="results"> <?php $obj = new Translator(); $commaSeparatedNums = $obj->splitString($_POST['string']); $translation = $obj->translate($commaSeparatedNums); echo implode(", ", $translation); ?> </div> </div> </div> </body> </html>