当前位置: 首页>>代码示例>>PHP>>正文


PHP Translator::transChoice方法代码示例

本文整理汇总了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');
 }
开发者ID:ESNFranceG33kTeam,项目名称:sf_buddysystem,代码行数:7,代码来源:MenteeType.php

示例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;
 }
开发者ID:petun,项目名称:ya-weather-speech,代码行数:14,代码来源:Composer.php

示例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));
 }
开发者ID:netixpro,项目名称:symfony,代码行数:10,代码来源:TranslatorTest.php

示例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]));
 }
开发者ID:ymarillet,项目名称:sknife,代码行数:12,代码来源:Datatable.php

示例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);
 }
开发者ID:keeko,项目名称:framework,代码行数:9,代码来源:KeekoTranslator.php

示例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));
     }
 }
开发者ID:WeavingTheWeb,项目名称:devobs,代码行数:20,代码来源:Accessor.php

示例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);
 }
开发者ID:VanillaPackage,项目名称:vanilla-validation,代码行数:23,代码来源:ValidationLocalize.php

示例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;
 }
开发者ID:WeavingTheWeb,项目名称:devobs,代码行数:21,代码来源:UserStatus.php

示例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)));
 }
开发者ID:Viduc,项目名称:tiremoidlaold,代码行数:9,代码来源:TranslatorTest.php

示例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());
 }
开发者ID:xinax,项目名称:laravel-gettext,代码行数:11,代码来源:Symfony.php

示例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;
 }
开发者ID:rattuscz,项目名称:Translation,代码行数:32,代码来源:Translator.php

示例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)));
    }
开发者ID:nattaphat,项目名称:hgis,代码行数:11,代码来源:TranslatorTest.php

示例13: transChoice

 public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null)
 {
     return $this->_translator->transChoice($id, $number, $parameters, $domain, $locale);
 }
开发者ID:puuble,项目名称:pubmvc,代码行数:4,代码来源:AdapterTranslatorSymfony.php

示例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);
 }
开发者ID:Silwereth,项目名称:core,代码行数:21,代码来源:Translator.php

示例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'));
 }
开发者ID:ryanhouston,项目名称:Behat,代码行数:13,代码来源:ConsoleFormatter.php


注:本文中的Symfony\Component\Translation\Translator::transChoice方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。