本文整理汇总了PHP中Symfony\Component\Translation\Translator::transChoice方法的典型用法代码示例。如果您正苦于以下问题:PHP Translator::transChoice方法的具体用法?PHP Translator::transChoice怎么用?PHP Translator::transChoice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Translation\Translator
的用法示例。
在下文中一共展示了Translator::transChoice方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildForm
public function buildForm(FormBuilderInterface $builder, array $options)
{
$section = $this->section;
$builder->add('prenom', "text")->add('nom', "text")->add('email', 'email')->add('sexe', 'choice', array('choices' => array('m' => $this->translator->trans('label.male'), 'f' => $this->translator->trans('label.female'))))->add('dob', 'date', array('required' => false, 'input' => 'datetime', 'widget' => 'single_text', 'format' => 'dd/MM/yyyy'))->add('arrival', 'date', array('required' => false, 'input' => 'datetime', 'widget' => 'single_text', 'format' => 'dd/MM/yyyy'))->add('nbsemester', 'choice', array('multiple' => false, 'expanded' => true, 'choices' => array(1 => "1 " . $this->translator->transChoice('label.semester', 1), 2 => "2 " . $this->translator->transChoice('label.semester', 2))))->add('submit', "submit")->add('password', 'repeated', array('type' => 'password', 'invalid_message' => 'Le mot de passe doit être indentique à sa confirmation.', 'required' => true))->add('conditionGenerale', 'checkbox', array('required' => true, 'label' => "J'accepte les conditions générales d'utilisations"))->add('nationalite', 'entity', array('label' => 'Status Name', 'empty_value' => $this->translator->trans('label.form.nationality'), 'class' => 'BuddySystem\\MembersBundle\\Entity\\Nationality', 'property' => 'nationality'))->add('universite', 'entity', array('label' => 'Status Name', 'empty_value' => 'crud.form.university', 'class' => 'BuddySystem\\MembersBundle\\Entity\\Univercity', 'query_builder' => function (UniversityRepository $ur) use($section) {
return $ur->getUniversitiesBySection($section, true);
}, 'required' => false))->add('comment');
}
示例2: _getChunks
private function _getChunks()
{
$tr = new Translator('ru_RU');
$tr->addLoader('array', new ArrayLoader());
$tr->addResource('array', ['degree|degree|degrees' => 'градус|градуса|градусов', 'percent' => 'процент|процента|процентов', 'mills' => 'миллиметр|миллиметра|миллиметров', 'hour' => 'час|часа|часов', 'minute' => 'минута|минуты|минут'], 'ru_RU');
$text = $tr->transChoice('degree|degree|degrees', $this->_info->getTemperature());
$humidity_text = $tr->transChoice('percent', $this->_info->getHumidity());
$pressure_text = $tr->transChoice('mills', $this->_info->getPressure());
$tempPrefixText = $this->_info->getTemperaturePrefix() == '-' ? 'минус' : '';
$time = date_parse($this->_info->getTime());
$timeStr = $time['hour'] . ' ' . $tr->transChoice('hour', $time['hour']) . ' ' . $time['minute'] . ' ' . $tr->transChoice('minute', $time['minute']);
$chunks = ['town' => $this->_info->getTown(), 'temp' => $tempPrefixText . " " . $this->_info->getTemperature() . " " . $text, 'type' => $this->_info->getWeatherType(), 'humidity' => $this->_info->getHumidity() . " " . $humidity_text, 'wind' => $this->_info->getWindDirection() . " " . $this->_info->getWindSpeed() . " метров в секунду", 'pressure' => $this->_info->getPressure() . " " . $pressure_text, 'time' => $timeStr];
return $chunks;
}
示例3: testTransChoice
/**
* @dataProvider getTransChoiceTests
*/
public function testTransChoice($expected, $id, $translation, $number, $parameters, $locale, $domain)
{
$translator = new Translator('en', new MessageSelector());
$translator->addLoader('array', new ArrayLoader());
$translator->addResource('array', array($id => $translation), $locale, $domain);
$this->assertEquals($expected, $translator->transChoice($id, $number, $parameters, $domain, $locale));
}
示例4: addCountSelectedFlashMessage
/**
* Adds a success message in the flashbag to indicate how many elements are selected
* @param mixed $tableId
* @author Yohann Marillet
*/
public function addCountSelectedFlashMessage($tableId)
{
$selected = $this->getSelected($tableId);
$nb = count($selected);
$message = '{0} Aucun élément n\'est sélectionné|{1} 1 élément est sélectionné|]1,Inf] %nb% éléments sont sélectionnés';
$this->session->getFlashBag()->add('success', $this->translator->transChoice($message, $nb, ['%nb%' => $nb]));
}
示例5: transChoice
public function transChoice($id, $number, array $parameters = [], $domain = null, $locale = null)
{
$params = $this->prepareParams($parameters);
// set domain if none passed but one is present
if ($this->domain !== null && $domain === null) {
$domain = $this->domain;
}
return parent::transChoice($id, $number, $params, $domain, $locale);
}
示例6: isApiRateLimitReached
/**
* @param string $endpoint
* @return bool
* @throws \Exception
*/
public function isApiRateLimitReached($endpoint = '/statuses/show/:id')
{
$rateLimitStatus = $this->fetchRateLimitStatus();
if ($this->hasError($rateLimitStatus)) {
$message = $rateLimitStatus->errors[0]->message;
$this->logger->error($message);
throw new \Exception($message, $rateLimitStatus->errors[0]->code);
} else {
$leastUpperBound = $rateLimitStatus->resources->statuses->{$endpoint}->limit;
$remainingCalls = $rateLimitStatus->resources->statuses->{$endpoint}->remaining;
$remainingCallsMessage = $this->translator->transChoice('logs.info.calls_remaining', $remainingCalls, ['{{ count }}' => $remainingCalls, '{{ endpoint }}' => $endpoint, '{{ identifier }}' => substr($this->userToken, 0, '8')], 'logs');
$this->logger->info($remainingCallsMessage);
return $remainingCalls < floor($leastUpperBound * (1 / 10));
}
}
示例7: translateFail
/**
* Translate a fail result.
*
* @param Fail $fail Fail to translate.
*
* @return string
*/
public function translateFail(Fail $fail)
{
$failData = $fail->getData();
$failTranslationKey = 'fail:' . $fail->rule->originalName;
$failTranslationData = array_combine(array_map([self::class, 'maskKey'], array_keys($failData)), array_values($failData));
// Fill field name or remove it.
$failTranslationDataFieldKey = $fail->field ? ':field' : ' ":field"';
$failTranslationData[$failTranslationDataFieldKey] = $fail->field ? $fail->field->name : null;
// If "quantify" data was defined, so use transChoice, instead.
if (array_key_exists(':quantify', $failTranslationData)) {
/** @noinspection ExceptionsAnnotatingAndHandlingInspection */
return self::$translator->transChoice($failTranslationKey, (int) $failTranslationData[':quantify'], $failTranslationData);
}
/** @noinspection ExceptionsAnnotatingAndHandlingInspection */
return self::$translator->trans($failTranslationKey, $failTranslationData);
}
示例8: saveStatuses
/**
* @param $options
* @return int|null
*/
protected function saveStatuses($options)
{
$statuses = $this->accessor->fetchTimelineStatuses($options);
$success = null;
if (is_array($statuses) && count($statuses) > 0) {
$statuses = $this->userStreamRepository->saveStatuses($statuses, $options['oauth']);
$statusesCount = count($statuses);
if ($statusesCount > 0) {
$success = $statusesCount;
$savedTweets = $this->translator->transChoice('logs.info.status_saved', $statusesCount, ['{{ user }}' => $options['screen_name'], '{{ count }}' => $statusesCount], 'logs');
$this->logger->info($savedTweets);
} else {
$this->logger->info('[nothing new for ' . $options['screen_name'] . ']');
}
}
return $success;
}
示例9: testTransChoiceFallbackWithNoTranslation
public function testTransChoiceFallbackWithNoTranslation()
{
$translator = new Translator('ru', new MessageSelector());
$translator->setFallbackLocales(array('en'));
$translator->addLoader('array', new ArrayLoader());
// consistent behavior with Translator::trans(), which returns the string
// unchanged if it can't be found
$this->assertEquals('some_message2', $translator->transChoice('some_message2', 10, array('%count%' => 10)));
}
示例10: translatePlural
/**
* Translates a plural string
*
* @param $singular
* @param $plural
* @param $amount
*/
public function translatePlural($singular, $plural, $amount)
{
return $this->symfonyTranslator->transChoice($amount > 1 ? $plural : $singular, $amount, ['%count%' => $amount], $this->getDomain(), $this->getLocale());
}
示例11: transChoice
/**
* {@inheritdoc}
*/
public function transChoice($message, $number, array $parameters = array(), $domain = NULL, $locale = NULL)
{
if ($message instanceof Phrase) {
return $message->translate($this);
}
if ($domain === NULL) {
list($domain, $id) = $this->extractMessageDomain($message);
} else {
$id = $message;
}
try {
$result = parent::transChoice($id, $number, $parameters, $domain, $locale);
} catch (\Exception $e) {
$result = $id;
if ($this->panel !== NULL) {
$this->panel->choiceError($e);
}
}
if ($result === "") {
if (!empty($this->onUntranslated)) {
$this->onUntranslated($message);
}
if ($this->panel !== NULL) {
$this->panel->markUntranslated($message);
}
$result = strtr($message, $parameters);
}
return $result;
}
示例12: testTransChoiceFallbackWithNoTranslation
/**
* @expectedException \InvalidArgumentException
*/
public function testTransChoiceFallbackWithNoTranslation()
{
$translator = new Translator('ru', new MessageSelector());
$translator->setFallbackLocale('en');
$translator->addLoader('array', new ArrayLoader());
$this->assertEquals('10 things', $translator->transChoice('some_message2', 10, array('%count%' => 10)));
}
示例13: transChoice
public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null)
{
return $this->_translator->transChoice($id, $number, $parameters, $domain, $locale);
}
示例14: transChoice
/**
* Translates the given choice message by choosing a translation according to a number.
*
* @param string $id The message id (may also be an object that can be cast to string)
* @param int $number The number to use to find the indice of the message
* @param array $parameters An array of parameters for the message
* @param string|null $domain The domain for the message or null to use the default
* @param string|null $locale The locale or null to use the default
*
* @throws \InvalidArgumentException If the locale contains invalid characters
*
* @return string The translated string
*
* @api
*/
public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null)
{
$domain = $domain == null ? $this->domain : $domain;
$locale = $locale == null ? $this->locale : $locale;
return parent::transChoice($id, $number, $parameters, $domain, $locale);
}
示例15: translateChoice
/**
* Translates numbered message to output language.
*
* @param string $message message specification to translate
* @param string $number choice number
* @param array $parameters message parameters
*
* @return string
*/
protected final function translateChoice($message, $number, array $parameters = array())
{
return $this->translator->transChoice($message, $number, $parameters, 'behat', $this->parameters->get('language'));
}