本文整理汇总了PHP中Thelia\Core\Translation\Translator类的典型用法代码示例。如果您正苦于以下问题:PHP Translator类的具体用法?PHP Translator怎么用?PHP Translator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Translator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: trans
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);
}
示例2: trans
protected function trans($id, $locale, $parameters = [])
{
if ($this->translator === null) {
$this->translator = Translator::getInstance();
}
return $this->translator->trans($id, $parameters, self::MODULE_DOMAIN, $locale);
}
示例3: registerValidatorTranslator
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');
}
示例4: getI18n
/**
* 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;
}
示例5: checkLocalizedDate
/**
* 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]));
}
}
示例6: verifyCountry
public function verifyCountry($value, ExecutionContextInterface $context)
{
$address = CountryQuery::create()->findPk($value);
if (null === $address) {
$context->addViolation(Translator::getInstance()->trans("Country ID not found"));
}
}
示例7: verifyExistingCode
public function verifyExistingCode($value, ExecutionContextInterface $context)
{
$coupon = CouponQuery::create()->findOneByCode($value);
if (null === $coupon) {
$context->addViolation(Translator::getInstance()->trans("This coupon does not exists"));
}
}
示例8: verifyProfileId
public function verifyProfileId($value, ExecutionContextInterface $context)
{
$profile = ProfileQuery::create()->findPk($value);
if (null === $profile) {
$context->addViolation(Translator::getInstance()->trans("Profile ID not found"));
}
}
示例9: verifyTaxList
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"));
}
}
}
}
示例10: buildForm
/**
* @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'));
}
示例11: checkCityName
public function checkCityName($value, ExecutionContextInterface $context)
{
$isValid = InseeGeoMunicipalityQuery::create()->findOneById($value);
if (!isset($isValid)) {
$context->addViolation(Translator::getInstance()->trans('city.error', [], INSEEGeo::DOMAIN_NAME));
}
}
示例12: checkAtLeastOnePhoneNumberIsDefined
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"));
}
}
示例13: verifyPasswordField
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"));
}
}
示例14: checkDuplicateRef
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)));
}
}
示例15: generateUrlFunction
/**
* 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;
}