当前位置: 首页>>代码示例>>PHP>>正文


PHP Application::getTranslator方法代码示例

本文整理汇总了PHP中Application::getTranslator方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::getTranslator方法的具体用法?PHP Application::getTranslator怎么用?PHP Application::getTranslator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Application的用法示例。


在下文中一共展示了Application::getTranslator方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: render

 /**
  * @param Context $ctx
  */
 public function render($ctx)
 {
     $this->ctx = $ctx;
     $path = $this->getTemplateDirPath() . "/" . $this->getTemplateName();
     global $form, $format;
     $form = $ctx->getForm();
     $format = $ctx->getUIManager()->getFormatter();
     // Make $page and $ui globals, so they can be accessed by the view template.
     global $page, $ui, $lang;
     $page = $this->getPage();
     $ui = $this->ctx->getUIManager();
     $lang = Application::getTranslator()->getLanguage();
     include $path;
 }
开发者ID:fruition-sciences,项目名称:phpfw,代码行数:17,代码来源:BaseView.php

示例2: doValidate

 /**
  * (non-PHPdoc)
  * @see Constraint::doValidate()
  */
 public function doValidate($ctx)
 {
     $value = $ctx->getRequest()->getString($this->getName(), '');
     // Validate only if there is a value
     if (!$value) {
         return true;
     }
     $converter = DataConverter::getInstance();
     if (!$converter->parseDate($value)) {
         $msg = sprintf(Application::getTranslator()->_('The field %1$s must be a valid date'), $this->getLabel());
         $this->addFieldError($ctx, $this->getName(), $msg);
         return false;
     }
     return true;
 }
开发者ID:fruition-sciences,项目名称:phpfw,代码行数:19,代码来源:DateConstraint.php

示例3: doValidate

 public function doValidate($ctx)
 {
     $value = $ctx->getRequest()->getString($this->getName(), null);
     if ($value === null) {
         $value = '';
         if (isset($_FILES[$this->getName()]['name'])) {
             $value = $_FILES[$this->getName()]['name'];
         }
     }
     if ($value == '') {
         $msg = sprintf(Application::getTranslator()->_('The field %1$s is required'), $this->getLabel());
         $this->addFieldError($ctx, $this->getName(), $msg);
         return false;
     }
     return true;
 }
开发者ID:fruition-sciences,项目名称:phpfw,代码行数:16,代码来源:RequiredConstraint.php

示例4: doValidate

 public function doValidate($ctx)
 {
     $formattedValue = $ctx->getRequest()->getString($this->getName(), null);
     // Validate only if there is a value
     if ($formattedValue === null || $formattedValue === '') {
         return true;
     }
     $format = new Formatter($ctx->getUser()->getTimezone(), $ctx->getUser()->getLocale());
     $value = $format->getNumber($formattedValue);
     if ($value === false) {
         $msg = sprintf(Application::getTranslator()->_('The field %1$s must be a valid number'), $this->getLabel());
         $this->addFieldError($ctx, $this->getName(), $msg);
         return false;
     }
     if ($this->minValue) {
         if ($this->minValue->isExclusive()) {
             if ($value <= $this->minValue->getValue()) {
                 $msg = sprintf(Application::getTranslator()->_('The value of the %1$s field must be greater than %2$s'), $this->getLabel(), $this->minValue->getValue());
                 $this->addFieldError($ctx, $this->getName(), $msg);
                 return false;
             }
         } else {
             if ($value < $this->minValue->getValue()) {
                 $msg = sprintf(Application::getTranslator()->_('The value of the %1$s field must be greater or equal to %2$s'), $this->getLabel(), $this->minValue->getValue());
                 $this->addFieldError($ctx, $this->getName(), $msg);
                 return false;
             }
         }
     }
     if ($this->maxValue) {
         if ($this->maxValue->isExclusive()) {
             if ($value >= $this->maxValue->getValue()) {
                 $msg = sprintf(Application::getTranslator()->_('The value of the %1$s field must be smaller than %2$s'), $this->getLabel(), $this->maxValue->getValue());
                 $this->addFieldError($ctx, $this->getName(), $msg);
                 return false;
             }
         } else {
             if ($value > $this->maxValue->getValue()) {
                 $msg = sprintf(Application::getTranslator()->_('The value of the %1$s field must be smaller or equal to %2$s'), $this->getLabel(), $this->maxValue->getValue());
                 $this->addFieldError($ctx, $this->getName(), $msg);
                 return false;
             }
         }
     }
     return true;
 }
开发者ID:fruition-sciences,项目名称:phpfw,代码行数:46,代码来源:NumberConstraint.php

示例5: invokeControllerMethod

 private function invokeControllerMethod()
 {
     $pathInfo = self::getPathInfo();
     $this->timeLogger->setText($pathInfo);
     $ctx = $this->getContext();
     $router = $this->loadRouter();
     $ctx->setRouter($router);
     $route = $router->match($pathInfo, $_SERVER);
     // If no route found, show a 404
     if (!$route) {
         throw new PageNotFoundException(Application::getTranslator()->_("Invalid URL."));
     }
     list($controllerAlias, $methodName, $lang, $redirectPath) = $this->getRouteResult($route);
     Logger::debug("Route: " . $route->name . " (controller={$controllerAlias}, method={$methodName}, lang={$lang}, redirect={$redirectPath})");
     $controllerClassName = null;
     try {
         $controllerClassName = $this->controllerClassNameFromAlias($controllerAlias);
     } catch (IllegalArgumentException $e) {
         throw new PageNotFoundException($e->getMessage(), 0, $e);
     }
     $ctx->setControllerAlias($controllerAlias);
     if (!class_exists($controllerClassName)) {
         throw new PageNotFoundException("Controller class not found: {$controllerClassName}");
     }
     $controller = new $controllerClassName();
     // Check if access is allowed. Controller will redirect if not.
     // TODO: Show a 403 if no access allowed
     if (!$controller->checkAccess($ctx)) {
         header('HTTP/1.1 403 Forbidden');
         return;
     }
     // If locale is required and set, but does not exist throw 404 error
     if ($controller->isLocaleSupported() && $lang && !in_array($lang, self::$translator->getAvailableLocales())) {
         throw new PageNotFoundException(Application::getTranslator()->_("Invalid URL."));
     }
     $locale = $this->getLocale($ctx, $controller, $lang);
     $supportedLocale = $this->getSupportedLocale($locale);
     /**
      * Support the 'redirect' directive of the route.
      * If the route included a 'redirect' value, we redirect to that path,
      * passing all route values + 'lang'.
      */
     if ($redirectPath) {
         $data = array_merge($route->params, array('lang' => $supportedLocale));
         $url = '/' . $router->generate($redirectPath, $data);
         // Include query string when redirecting
         $qs = $_SERVER['QUERY_STRING'];
         if ($qs) {
             $url .= "?{$qs}";
         }
         $ctx->redirect($url, true);
     }
     I18nUtil::setDefaultLocale($supportedLocale);
     self::$translator->setLocale($supportedLocale);
     header('Content-Language: ' . self::$translator->getLocale());
     // Allow dashes in method name (for SEO purposes). Converts to camelCase.
     $methodName = $this->camelize($methodName);
     if (!method_exists($controller, $methodName)) {
         throw new PageNotFoundException("Missing action method '{$methodName}' in controller {$controllerClassName}");
     }
     $view = null;
     // Invoke the controller's method
     try {
         $view = $controller->{$methodName}($ctx);
     } catch (ForwardViewException $e) {
         // Hanlde 'forwarding': A controller method threw this exception
         // containing a view instead of returning it in a normal way.
         $view = $e->getView();
     }
     if ($view instanceof View) {
         if ($ctx->getUIManager()->getErrorManager()->hasErrors()) {
             $ctx->getForm()->setValues($ctx->getAttributes());
         }
         if (self::$translator) {
             $view->setTranslator(self::$translator);
         }
         $view->init($ctx);
         global $form;
         $view->render($ctx);
     }
 }
开发者ID:fruition-sciences,项目名称:phpfw,代码行数:81,代码来源:Application.php

示例6: getDatePickerLocalization

 /**
  * Localization array for the Jquery UI date time picker.
  * @return array
  */
 private function getDatePickerLocalization()
 {
     $daysArr = Zend_Locale_Data::getList(Transaction::getInstance()->getUser()->getLocale(), "days");
     $weekArr = Zend_Locale_Data::getList(Transaction::getInstance()->getUser()->getLocale(), "week");
     $firstDay = $daysArr['format']['narrow'][$weekArr["firstDay"]] - 1;
     $tr = Application::getTranslator();
     // Most i18n values come from dedicated jquery.ui.datepicker-<LANG>.js
     // Make sure to include this file on all pages.
     // The fields defined here are the ones used by the datetimepicker extension.
     $regional = array("closeText" => $tr->_('Done'), "dateFormat" => $tr->_('m/dd/yy'), "firstDay" => $firstDay, "isRTL" => false, "showMonthAfterYear" => false, "yearSuffix" => '');
     if ($this->showTime) {
         $regional["currentText"] = $tr->_('Now');
         $regional["amNames"] = array('AM', 'A');
         $regional["pmNames"] = array('PM', 'P');
         // Important: timeFormat must be compatible with pattern used by Formatter::datetime for each locale
         $regional["timeFormat"] = $tr->_('h:mm TT');
         $regional["timeSuffix"] = '';
         $regional["timeOnlyTitle"] = $tr->_('Choose Time');
         $regional["timeText"] = $tr->_('Time');
         $regional["hourText"] = $tr->_('Hour');
         $regional["minuteText"] = $tr->_('Minute');
         $regional["secondText"] = $tr->_('Second');
         $regional["millisecText"] = $tr->_('Millisecond');
         $regional["timezoneText"] = $tr->_('Time Zone');
     }
     return $regional;
 }
开发者ID:fruition-sciences,项目名称:phpfw,代码行数:31,代码来源:Datebox.php

示例7: getDatePattern

 /**
  * Get the pattern to be used to format and parse date/time.
  * The pattern is locale specific.
  * The returned pattern is according to this specification: http://userguide.icu-project.org/formatparse/datetime
  * 
  * Note:
  * 1. The $locale parameter is here becuase it *should* be used, however
  *    current implementation uses Application::getTranslator(), which is
  *    static so locale is not being use. It should be changed to use the given locale.
  * 2. Calls to the translator should explicitly send the literal pattern so
  *    that it is picked by the translator parser. (poedit).
  * 
  * @param String $locale
  * @param boolean $withDate whether the pattern should include date. Default is true.
  * @param boolean $withTime whether the pattern should include time. Default is false.
  * @param boolean $timeIncludesSeconds whether the time should include seconds. Default is false.
  *        Relevant only if $withTime is true.
  *        Note: Currently ignored if $withDate is true.
  * @return String
  */
 public static function getDatePattern($locale, $withDate = true, $withTime = false, $timeIncludesSeconds = false)
 {
     if (!$withDate && !$withTime) {
         throw new IllegalArgumentException("Date format must contain date or/and time");
     }
     $translator = Application::getTranslator();
     if ($withDate && $withTime) {
         return $translator->_('M/dd/yy h:mm a');
     }
     if ($withDate) {
         return $translator->_('M/dd/yy');
     }
     if ($withTime) {
         return $timeIncludesSeconds ? $translator->_('h:mm:ss a') : $translator->_('h:mm a');
     }
 }
开发者ID:fruition-sciences,项目名称:phpfw,代码行数:36,代码来源:DataConverter.php

示例8: getMonthsArray

 /**
  * Return an array containing all the months
  * The key is the month number and the value is the formatted month
  *
  * @param string $format "abbreviated" ("jan.") or "wide" ("janvier").
  * @return array containing the 12 months. January is in index 1.
  */
 public static function getMonthsArray($format)
 {
     $zendMonthArr = Zend_Locale::getTranslationList("months", Application::getTranslator()->getLocale());
     return $zendMonthArr["format"][$format];
 }
开发者ID:fruition-sciences,项目名称:phpfw,代码行数:12,代码来源:DateUtils.php


注:本文中的Application::getTranslator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。