本文整理汇总了PHP中Symfony\Component\Translation\TranslatorInterface::transChoice方法的典型用法代码示例。如果您正苦于以下问题:PHP TranslatorInterface::transChoice方法的具体用法?PHP TranslatorInterface::transChoice怎么用?PHP TranslatorInterface::transChoice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Translation\TranslatorInterface
的用法示例。
在下文中一共展示了TranslatorInterface::transChoice方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: format
public function format(DateDiffResult $result)
{
if ($result->getKey() === DateDiffResult::FULL_DATE) {
return $result->getRequest()->getDate()->format($this->dateFormat);
}
return $this->translatorInterface->transChoice($result->getKey(), $result->getValue(), $this->getPlaceholders($result), $this->domain);
}
示例2: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (empty($options['data_class'])) {
return;
}
$className = $options['data_class'];
if (!$this->doctrineHelper->isManageableEntity($className)) {
return;
}
if (!$this->entityConfigProvider->hasConfig($className)) {
return;
}
$uniqueKeys = $this->entityConfigProvider->getConfig($className)->get('unique_key');
if (empty($uniqueKeys)) {
return;
}
/* @var \Symfony\Component\Validator\Mapping\ClassMetadata $validatorMetadata */
$validatorMetadata = $this->validator->getMetadataFor($className);
foreach ($uniqueKeys['keys'] as $uniqueKey) {
$fields = $uniqueKey['key'];
$labels = array_map(function ($fieldName) use($className) {
$label = $this->entityConfigProvider->getConfig($className, $fieldName)->get('label');
return $this->translator->trans($label);
}, $fields);
$constraint = new UniqueEntity(['fields' => $fields, 'errorPath' => '', 'message' => $this->translator->transChoice('oro.entity.validation.unique_field', sizeof($fields), ['%field%' => implode(', ', $labels)])]);
$validatorMetadata->addConstraint($constraint);
}
}
示例3: translateMessage
private function translateMessage(TranslatableNotificationMessage $message)
{
if ($message->number !== null) {
return $this->translator->transChoice($message->message, (int) $message->number, $message->translationParams, $message->domain);
}
return $this->translator->trans($message->message, $message->translationParams, $message->domain);
}
示例4: formatData
/**
* @param float|integer $value
* @param ProductUnit $unit
* @param boolean $isShort
* @return string
*/
protected function formatData($value, ProductUnit $unit, $isShort = false)
{
if (!is_numeric($value)) {
throw new \InvalidArgumentException(sprintf('The parameter "value" must be a numeric, but it is of type %s.', gettype($value)));
}
$translationKey = sprintf('orob2b.product_unit.%s.value.' . ($isShort ? 'short' : 'full'), $unit->getCode());
return $this->translator->transChoice($translationKey, $value, ['%count%' => $value]);
}
示例5: getSuccessMessage
/**
* @param int $shoppingListId
* @param int $entitiesCount
* @param null|string $transChoiceKey
* @return string
*/
public function getSuccessMessage($shoppingListId = null, $entitiesCount = 0, $transChoiceKey = null)
{
$message = $this->translator->transChoice($transChoiceKey ?: 'orob2b.shoppinglist.actions.add_success_message', $entitiesCount, ['%count%' => $entitiesCount]);
if ($shoppingListId && $entitiesCount > 0) {
$message = sprintf('%s (<a href="%s">%s</a>).', $message, $this->router->generate('orob2b_shopping_list_frontend_view', ['id' => $shoppingListId]), $linkTitle = $this->translator->trans('orob2b.shoppinglist.actions.view'));
}
return $message;
}
示例6: formatCommaSeparatedWithLimit
/**
* @param $collection
* @param $limit
* @param $count
*
* @return string
*/
private function formatCommaSeparatedWithLimit($collection, $limit, $count)
{
$display = array_map(function ($element) {
return (string) $element;
}, array_slice($collection, 0, $limit));
$moreCount = $count - count($display);
return $this->translator->transChoice('comma_separated_with_limit', $moreCount, array('%list%' => implode(', ', $display), '%count%' => $moreCount), $this->catalogue);
}
示例7: getResponse
protected function getResponse(MassActionHandlerArgs $args, $count = 0)
{
$massAction = $args->getMassAction();
$responseMessage = $massAction->getOptions()->offsetGetByPath('[messages][success]', $this->responseMessage);
$successful = $count > 0;
$options = ['count' => $count];
return new MassActionResponse($successful, $this->translator->transChoice($responseMessage, $count, ['%count%' => $count]), $options);
}
示例8: formatDifference
/**
* @param PreciseDifference $difference
* @param string $locale
*
* @return string
*/
public function formatDifference(PreciseDifference $difference, $locale = 'en')
{
$diff = array();
foreach ($difference->getCompoundResults() as $result) {
$diff[] = $this->translator->transChoice('compound.' . $result->getUnit()->getName(), $result->getQuantity(), array('%count%' => $result->getQuantity()), 'difference', $locale);
}
return $this->translator->trans('compound.' . ($difference->isPast() ? 'past' : 'future'), array('%value%' => implode(', ', $diff)), 'difference', $locale);
}
示例9: trans
private function trans($context, $args, $count, $bundle, $locale)
{
if (is_null($count)) {
$trans = $this->translator->trans($context, $args, $bundle, $locale);
} else {
$trans = $this->translator->transChoice($context, $count, $args, $bundle, $locale);
}
return $trans;
}
示例10: formatDifference
/**
* @param PreciseDifference $difference
* @param string $locale
* @return string
*/
public function formatDifference(PreciseDifference $difference, $locale = 'en')
{
$diff = array();
foreach ($difference->getCompoundResults() as $result) {
$diff[] = $this->translator->transChoice("compound." . $result->getUnit()->getName(), $result->getQuantity(), array('%count%' => $result->getQuantity()), 'difference', $locale);
}
$suffix = $difference->isPast() ? 'compound.ago' : 'compound.from_now';
return join(", ", $diff) . ' ' . $this->translator->trans($suffix, array(), 'difference', $locale);
}
示例11: getAgeAsString
/**
* Get translated age string.
*
* @param string|\DateTime $date
* @param array $options
* @return string
*/
public function getAgeAsString($date, $options)
{
$dateDiff = $this->getDateDiff($date, $options);
if (!$dateDiff->invert) {
$age = $dateDiff->y;
return $this->translator->transChoice('oro.age', $age, array('%count%' => $age), 'messages');
} else {
return isset($options['default']) ? $options['default'] : '';
}
}
示例12: transChoice
/**
* {@inheritdoc}
*/
public function transChoice($id, $number, array $parameters = [], $domain = null, $locale = null)
{
$possibleIds = $this->getPossibleIds($id);
foreach ($possibleIds as $possibleId) {
$translation = $this->translator->transChoice($possibleId, $number, $parameters, $domain, $locale);
if ($translation !== $possibleId) {
return $translation;
}
}
return $id;
}
示例13: getPluralizedInterval
protected function getPluralizedInterval($count, $invert, $unit)
{
if ($this->translator) {
$id = sprintf('diff.%s.%s', $invert ? 'in' : 'ago', $unit);
return $this->translator->transChoice($id, $count, array('%count%' => $count), 'date');
}
if (1 !== $count) {
$unit .= 's';
}
return $invert ? "in {$count} {$unit}" : "{$count} {$unit} ago";
}
示例14: visitMenuItem
public function visitMenuItem(MenuItem $item)
{
$domain = $item->getExtra('translation_domain');
$parameters = $item->getExtra('translation_parameters');
if (false === $parameters) {
return;
} elseif (!is_array($parameters)) {
$parameters = [];
}
$id = $item->getLabel();
if (null !== ($number = $item->getExtra('translation_number'))) {
$item->setLabel($this->translator->transChoice($id, $number, $parameters, $domain));
} else {
$item->setLabel($this->translator->trans($id, $parameters, $domain));
}
}
示例15: getInfoMessage
/**
* @param object $entity
* @param string $scope
* @return string|null
*/
public function getInfoMessage($entity, $scope = EntityPaginationManager::VIEW_SCOPE)
{
$entityName = ClassUtils::getClass($entity);
// info message should be shown only once for each scope
if (false !== $this->storage->isInfoMessageShown($entityName, $scope)) {
return null;
}
$viewCount = $this->navigation->getTotalCount($entity, EntityPaginationManager::VIEW_SCOPE);
$editCount = $this->navigation->getTotalCount($entity, EntityPaginationManager::EDIT_SCOPE);
if (!$viewCount || !$editCount || $viewCount == $editCount) {
return null;
}
$message = '';
$count = null;
// if scope is changing from "view" to "edit" and number of entities is decreased
if ($scope == EntityPaginationManager::EDIT_SCOPE) {
if ($editCount < $viewCount) {
$message .= $this->translator->trans('oro.entity_pagination.message.stats_changed_view_to_edit') . ' ';
}
$count = $editCount;
} elseif ($scope == EntityPaginationManager::VIEW_SCOPE) {
$count = $viewCount;
}
if (!$count) {
return null;
}
$message .= $this->translator->transChoice($this->getStatsMessage($scope), $count, ['%count%' => $count]);
$this->storage->setInfoMessageShown($entityName, $scope);
return $message;
}