本文整理汇总了PHP中Symfony\Component\Translation\TranslatorInterface::transchoice方法的典型用法代码示例。如果您正苦于以下问题:PHP TranslatorInterface::transchoice方法的具体用法?PHP TranslatorInterface::transchoice怎么用?PHP TranslatorInterface::transchoice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Translation\TranslatorInterface
的用法示例。
在下文中一共展示了TranslatorInterface::transchoice方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: showAction
/**
* Show a job executions report
*
* @param Request $request
* @param int $id
*
* @return \Symfony\Component\HttpFoundation\Response|JsonResponse
*/
public function showAction(Request $request, $id)
{
$jobExecution = $this->findOr404('Akeneo\\Component\\Batch\\Model\\JobExecution', $id);
$this->eventDispatcher->dispatch(JobExecutionEvents::PRE_SHOW, new GenericEvent($jobExecution));
if ('json' === $request->getRequestFormat()) {
$archives = [];
foreach ($this->archivist->getArchives($jobExecution) as $archiveName => $files) {
$label = $this->translator->transchoice(sprintf('pim_import_export.download_archive.%s', $archiveName), count($files));
$archives[$archiveName] = ['label' => ucfirst($label), 'files' => $files];
}
if (!$this->jobExecutionManager->checkRunningStatus($jobExecution)) {
$this->jobExecutionManager->markAsFailed($jobExecution);
}
// limit the number of step execution returned to avoid memory overflow
$context = ['limit_warnings' => 100];
return new JsonResponse(['jobExecution' => $this->serializer->normalize($jobExecution, 'json', $context), 'hasLog' => file_exists($jobExecution->getLogFile()), 'archives' => $archives]);
}
return $this->render('PimEnrichBundle:JobTracker:show.html.twig', ['execution' => $jobExecution]);
}
示例2: distanceOfTimeInWordsFilter
/**
* Reports the approximate distance in time between two times given in seconds
* or in a valid ISO string like.
* For example, if the distance is 47 minutes, it'll return
* "about 1 hour". See the source for the complete wording list.
*
* Integers are interpreted as seconds. So, by example to check the distance of time between
* a created user and their last login:
* {{ user.createdAt|distance_of_time_in_words(user.lastLoginAt) }} returns "less than a minute".
*
* Set include_seconds to true if you want more detailed approximations if distance < 1 minute
* Set include_months to true if you want approximations in months if days > 30
*
* @param string|\DateTime $from_time
* @param string|\DateTime $to_time
* @param bool $include_seconds True to return distance in seconds when it's lower than a minute.
* @param bool $include_months
*
* @return string
*/
public function distanceOfTimeInWordsFilter($from_time, $to_time = null, $include_seconds = false, $include_months = false)
{
$datetime_transformer = new DateTimeToStringTransformer(null, null, 'Y-m-d H:i:s');
$timestamp_transformer = new DateTimeToTimestampTransformer();
// Transform “from” to timestamp
if ($from_time instanceof \DateTime) {
$from_time = $timestamp_transformer->transform($from_time);
} elseif (!is_numeric($from_time)) {
$from_time = $datetime_transformer->reverseTransform($from_time);
$from_time = $timestamp_transformer->transform($from_time);
}
$to_time = empty($to_time) ? new \DateTime('now') : $to_time;
// Transform “to” to timestamp
if ($to_time instanceof \DateTime) {
$to_time = $timestamp_transformer->transform($to_time);
} elseif (!is_numeric($to_time)) {
$to_time = $datetime_transformer->reverseTransform($to_time);
$to_time = $timestamp_transformer->transform($to_time);
}
$future = $to_time < $from_time;
$distance_in_minutes = round(abs($to_time - $from_time) / 60);
$distance_in_seconds = round(abs($to_time - $from_time));
if ($future) {
return $this->future($distance_in_minutes, $include_seconds, $distance_in_seconds);
}
if ($distance_in_minutes <= 1) {
if ($include_seconds) {
if ($distance_in_seconds < 5) {
return $this->translator->trans('less than %seconds seconds ago', array('%seconds' => 5));
}
if ($distance_in_seconds < 10) {
return $this->translator->trans('less than %seconds seconds ago', array('%seconds' => 10));
}
if ($distance_in_seconds < 20) {
return $this->translator->trans('less than %seconds seconds ago', array('%seconds' => 20));
}
if ($distance_in_seconds < 40) {
return $this->translator->trans('half a minute ago');
}
if ($distance_in_seconds < 60) {
return $this->translator->trans('less than a minute ago');
}
return $this->translator->trans('1 minute ago');
}
return $distance_in_minutes == 0 ? $this->translator->trans('less than a minute ago') : $this->translator->trans('1 minute ago');
}
if ($distance_in_minutes <= 45) {
return $this->translator->trans('%minutes minutes ago', array('%minutes' => $distance_in_minutes));
}
if ($distance_in_minutes <= 90) {
return $this->translator->trans('about 1 hour ago');
}
if ($distance_in_minutes <= 1440) {
return $this->translator->trans('about %hours hours ago', array('%hours' => round($distance_in_minutes / 60)));
}
if ($distance_in_minutes <= 2880) {
return $this->translator->trans('1 day ago');
}
$distance_in_days = round($distance_in_minutes / 1440);
if (!$include_months || $distance_in_days <= 30) {
return $this->translator->trans('%days days ago', array('%days' => round($distance_in_days)));
}
if ($distance_in_days < 345) {
return $this->translator->transchoice('{1} 1 month ago |]1,Inf[ %months months ago', round($distance_in_days / 30), array('%months' => round($distance_in_days / 30)));
}
return $this->translator->transchoice('{1} 1 year ago |]1,Inf[ %years years ago', round($distance_in_days / 365), array('%years' => round($distance_in_days / 365)));
}