php Thelia-Core-Translation-Translator类(方法)实例源码

下面列出了php Thelia-Core-Translation-Translator 类(方法)源码代码实例,从而了解它的用法。

作者:marger    项目:theli   
protected function trans($id, $parameters = [], $locale = null)
 {
     if (null === $this->translator) {
         $this->translator = Translator::getInstance();
     }
     return $this->translator->trans($id, $parameters, self::MESSAGE_DOMAIN, $locale);
 }

作者:Asena    项目:thelia-FreeShippin   
protected function trans($id, $locale, $parameters = [])
 {
     if ($this->translator === null) {
         $this->translator = Translator::getInstance();
     }
     return $this->translator->trans($id, $parameters, self::MODULE_DOMAIN, $locale);
 }

作者:NandoKstroNe    项目:theli   
public function registerValidatorTranslator(GetResponseEvent $event)
 {
     /** @var \Thelia\Core\HttpFoundation\Request $request */
     $request = $event->getRequest();
     $lang = $request->getSession()->getLang();
     $vendorFormDir = THELIA_VENDOR . 'symfony' . DS . 'form' . DS . 'Symfony' . DS . 'Component' . DS . 'Form';
     $vendorValidatorDir = THELIA_VENDOR . 'symfony' . DS . 'validator' . DS . 'Symfony' . DS . 'Component' . DS . 'Validator';
     $this->translator->addResource('xlf', sprintf($vendorFormDir . DS . 'Resources' . DS . 'translations' . DS . 'validators.%s.xlf', $lang->getCode()), $lang->getLocale(), 'validators');
     $this->translator->addResource('xlf', sprintf($vendorValidatorDir . DS . 'Resources' . DS . 'translations' . DS . 'validators.%s.xlf', $lang->getCode()), $lang->getLocale(), 'validators');
 }

作者:marger    项目:theli   
/**
  * Get operator translation
  *
  * @param Translator $translator Provide necessary value from Thelia
  * @param string     $operator   Operator const
  *
  * @return string
  */
 public static function getI18n(Translator $translator, $operator)
 {
     $ret = $operator;
     switch ($operator) {
         case self::INFERIOR:
             $ret = $translator->trans('Less than', []);
             break;
         case self::INFERIOR_OR_EQUAL:
             $ret = $translator->trans('Less than or equals', []);
             break;
         case self::EQUAL:
             $ret = $translator->trans('Equal to', []);
             break;
         case self::SUPERIOR_OR_EQUAL:
             $ret = $translator->trans('Greater than or equals', []);
             break;
         case self::SUPERIOR:
             $ret = $translator->trans('Greater than', []);
             break;
         case self::DIFFERENT:
             $ret = $translator->trans('Not equal to', []);
             break;
         case self::IN:
             $ret = $translator->trans('In', []);
             break;
         case self::OUT:
             $ret = $translator->trans('Not in', []);
             break;
         default:
     }
     return $ret;
 }

作者:alex6353    项目:theli   
/**
  * Validate a date entered with the default Language date format.
  *
  * @param string                    $value
  * @param ExecutionContextInterface $context
  */
 public function checkLocalizedDate($value, ExecutionContextInterface $context)
 {
     $format = LangQuery::create()->findOneByByDefault(true)->getDateFormat();
     if (false === \DateTime::createFromFormat($format, $value)) {
         $context->addViolation(Translator::getInstance()->trans("Date '%date' is invalid, please enter a valid date using %fmt format", ['%fmt' => $format, '%date' => $value]));
     }
 }

作者:manuelbc    项目:theli   
public function verifyCountry($value, ExecutionContextInterface $context)
 {
     $address = CountryQuery::create()->findPk($value);
     if (null === $address) {
         $context->addViolation(Translator::getInstance()->trans("Country ID not found"));
     }
 }

作者:alex6353    项目:theli   
public function verifyExistingCode($value, ExecutionContextInterface $context)
 {
     $coupon = CouponQuery::create()->findOneByCode($value);
     if (null === $coupon) {
         $context->addViolation(Translator::getInstance()->trans("This coupon does not exists"));
     }
 }

作者:marger    项目:theli   
public function verifyProfileId($value, ExecutionContextInterface $context)
 {
     $profile = ProfileQuery::create()->findPk($value);
     if (null === $profile) {
         $context->addViolation(Translator::getInstance()->trans("Profile ID not found"));
     }
 }

作者:alex6353    项目:theli   
public function verifyTaxList($value, ExecutionContextInterface $context)
 {
     $jsonType = new JsonType();
     if (!$jsonType->isValid($value)) {
         $context->addViolation(Translator::getInstance()->trans("Tax list is not valid JSON"));
     }
     $taxList = json_decode($value, true);
     /* check we have 2 level max */
     foreach ($taxList as $taxLevel1) {
         if (is_array($taxLevel1)) {
             foreach ($taxLevel1 as $taxLevel2) {
                 if (is_array($taxLevel2)) {
                     $context->addViolation(Translator::getInstance()->trans("Bad tax list JSON"));
                 } else {
                     $taxModel = TaxQuery::create()->findPk($taxLevel2);
                     if (null === $taxModel) {
                         $context->addViolation(Translator::getInstance()->trans("Tax ID not found in tax list JSON"));
                     }
                 }
             }
         } else {
             $taxModel = TaxQuery::create()->findPk($taxLevel1);
             if (null === $taxModel) {
                 $context->addViolation(Translator::getInstance()->trans("Tax ID not found in tax list JSON"));
             }
         }
     }
 }

作者:NandoKstroNe    项目:theli   
/**
  * @inherited
  */
 protected function buildForm()
 {
     $translator = Translator::getInstance();
     BaseProductCreationForm::buildForm();
     $this->formBuilder->add("brand_id", "integer", ['required' => true, 'label' => $translator->trans('Brand / Supplier'), 'label_attr' => ['for' => 'mode', 'help' => $translator->trans("Select the product brand, or supplier.")]]);
     $this->addStandardDescFields(array('title', 'locale'));
 }

作者:enuri    项目:INSEEGe   
public function checkCityName($value, ExecutionContextInterface $context)
 {
     $isValid = InseeGeoMunicipalityQuery::create()->findOneById($value);
     if (!isset($isValid)) {
         $context->addViolation(Translator::getInstance()->trans('city.error', [], INSEEGeo::DOMAIN_NAME));
     }
 }

作者:thelia-module    项目:ForcePhon   
public function checkAtLeastOnePhoneNumberIsDefined($value, ExecutionContextInterface $context)
 {
     $data = $context->getRoot()->getData();
     if (empty($data["phone"]) && empty($data["cellphone"])) {
         $context->addViolationAt("phone", Translator::getInstance()->trans("Please enter a home or mobile phone number"));
     }
 }

作者:vigourouxjulie    项目:theli   
public function verifyPasswordField($value, ExecutionContextInterface $context)
 {
     $data = $context->getRoot()->getData();
     if ($data["password"] != $data["password_confirm"]) {
         $context->addViolation(Translator::getInstance()->trans("password confirmation is not the same as password field"));
     }
 }

作者:marger    项目:theli   
public function checkDuplicateRef($value, ExecutionContextInterface $context)
 {
     $count = ProductQuery::create()->filterByRef($value)->count();
     if ($count > 0) {
         $context->addViolation(Translator::getInstance()->trans("A product with reference %ref already exists. Please choose another reference.", array('%ref' => $value)));
     }
 }

作者:NandoKstroNe    项目:theli   
/**
  * Process url generator function
  *
  * @param  array   $params
  * @param  \Smarty $smarty
  * @return string  no text is returned.
  */
 public function generateUrlFunction($params, &$smarty)
 {
     // the path to process
     $current = $this->getParam($params, 'current', false);
     $path = $this->getParam($params, 'path', null);
     $file = $this->getParam($params, 'file', null);
     // Do not invoke index.php in URL (get a static file in web space
     if ($current) {
         $path = $this->request->getPathInfo();
         unset($params["current"]);
         // Delete the current param, so it isn't included in the url
         // Then build the query variables
         $params = array_merge($this->request->query->all(), $params);
     }
     if ($file !== null) {
         $path = $file;
         $mode = URL::PATH_TO_FILE;
     } elseif ($path !== null) {
         $mode = URL::WITH_INDEX_PAGE;
     } else {
         throw new \InvalidArgumentException(Translator::getInstance()->trans("Please specify either 'path' or 'file' parameter in {url} function."));
     }
     $excludeParams = $this->resolvePath($params, $path, $smarty);
     $url = URL::getInstance()->absoluteUrl($path, $this->getArgsFromParam($params, array_merge(['noamp', 'path', 'file', 'target'], $excludeParams)), $mode);
     $this->applyNoAmpAndTarget($params, $url);
     return $url;
 }

作者:bobanmilan    项目:theli   
public function verifyExistingEmail($value, ExecutionContextInterface $context)
 {
     $customer = NewsletterQuery::create()->filterByUnsubscribed(false)->findOneByEmail($value);
     if ($customer) {
         $context->addViolation(Translator::getInstance()->trans("You are already registered!"));
     }
 }

作者:marger    项目:theli   
/**
  * @inheritdoc
  */
 protected function buildForm()
 {
     $translator = Translator::getInstance();
     $this->formBuilder->add('file', 'file', ['required' => false, 'constraints' => [new Image([])], 'label' => $translator->trans('Replace current image by this file'), 'label_attr' => ['for' => 'file']])->add('visible', 'checkbox', ['constraints' => [], 'required' => false, 'label' => $translator->trans('This image is online'), 'label_attr' => ['for' => 'visible_create']]);
     // Add standard description fields
     $this->addStandardDescFields();
 }

作者:marger    项目:theli   
public function verifyExistingEmail($value, ExecutionContextInterface $context)
 {
     $customer = CustomerQuery::getCustomerByEmail($value);
     if ($customer) {
         $context->addViolation(Translator::getInstance()->trans("This email already exists."));
     }
 }

作者:vigourouxjulie    项目:theli   
public function checkDuplicateCode($value, ExecutionContextInterface $context)
 {
     $currency = CurrencyQuery::create()->findOneByCode($value);
     if ($currency) {
         $context->addViolation(Translator::getInstance()->trans('A currency with code "%name" already exists.', ['%name' => $value]));
     }
 }

作者:roadster3    项目:TNTFranc   
protected function trans($id, $parameters = [])
 {
     if (null === $this->translator) {
         $this->translator = Translator::getInstance();
     }
     return $this->translator->trans($id, $parameters, $this->domain);
 }


问题


面经


文章

微信
公众号

扫码关注公众号