本文整理汇总了PHP中Symfony\Component\Translation\TranslatorInterface::getCatalogue方法的典型用法代码示例。如果您正苦于以下问题:PHP TranslatorInterface::getCatalogue方法的具体用法?PHP TranslatorInterface::getCatalogue怎么用?PHP TranslatorInterface::getCatalogue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Translation\TranslatorInterface
的用法示例。
在下文中一共展示了TranslatorInterface::getCatalogue方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tryTranslate
/**
* Will check the translator for the key "eav.family.{$code}.label"
* and humanize the code if no translation is found
*
* @param string|array $tIds
* @param array $parameters
* @param string $fallback
* @param bool $humanizeFallback
* @return string
*/
protected function tryTranslate($tIds, array $parameters = [], $fallback = null, $humanizeFallback = true)
{
if (!is_array($tIds)) {
$tIds = [$tIds];
}
foreach ($tIds as $tId) {
try {
if ($this->translator instanceof TranslatorBagInterface) {
if ($this->translator->getCatalogue()->has($tId)) {
/** @noinspection PhpUndefinedMethodInspection */
return $this->translator->trans($tId, $parameters);
}
} elseif ($this->translator instanceof TranslatorInterface) {
$label = $this->translator->trans($tId, $parameters);
if ($label !== $tId) {
return $label;
}
}
} catch (\InvalidArgumentException $e) {
// Do nothing
}
}
if ($fallback === null) {
return null;
}
if (!$humanizeFallback) {
return $fallback;
}
$pattern = '/(?!^)[A-Z]{2,}(?=[A-Z][a-z])|[A-Z][a-z]|\\d{1,}/';
return str_replace('_', ' ', preg_replace($pattern, ' $0', $fallback));
}
示例2: transchoiceWithDefault
/**
* @param string $message
* @param string $defaultMessage
* @param int $count
* @param array $arguments
* @param null|string $domain
* @param null|string $locale
* @return string
*/
public function transchoiceWithDefault($message, $defaultMessage, $count, array $arguments = array(), $domain = null, $locale = null)
{
if (null === $domain) {
$domain = 'messages';
}
// If < sf2.6
if (!method_exists($this->translator, 'getCatalogue')) {
return $this->transchoiceWithDefaultLegacy($message, $defaultMessage, $count, $arguments, $domain, $locale);
}
if (false == $this->translator->getCatalogue($locale)->defines($message, $domain)) {
return $this->translator->transChoice($defaultMessage, $count, array_merge(array('%count%' => $count), $arguments), $domain, $locale);
}
return $this->translator->transChoice($message, $count, array_merge(array('%count%' => $count), $arguments), $domain, $locale);
}
示例3: collectMessage
/**
* @param string|null $locale
* @param string|null $domain
* @param string $id
* @param string $translation
* @param array|null $parameters
* @param int|null $number
*/
private function collectMessage($locale, $domain, $id, $translation, $parameters = array(), $number = null)
{
if (null === $domain) {
$domain = 'messages';
}
$id = (string) $id;
$catalogue = $this->translator->getCatalogue($locale);
$locale = $catalogue->getLocale();
if ($catalogue->defines($id, $domain)) {
$state = self::MESSAGE_DEFINED;
} elseif ($catalogue->has($id, $domain)) {
$state = self::MESSAGE_EQUALS_FALLBACK;
$fallbackCatalogue = $catalogue->getFallbackCatalogue();
while ($fallbackCatalogue) {
if ($fallbackCatalogue->defines($id, $domain)) {
$locale = $fallbackCatalogue->getLocale();
break;
}
$fallbackCatalogue = $fallbackCatalogue->getFallbackCatalogue();
}
} else {
$state = self::MESSAGE_MISSING;
}
$this->messages[] = array('locale' => $locale, 'domain' => $domain, 'id' => $id, 'translation' => $translation, 'parameters' => $parameters, 'transChoiceNumber' => $number, 'state' => $state);
}
示例4: getUiLocale
/**
* @param \OAuth2\Endpoint\Authorization\AuthorizationInterface $authorization
*
* @return null|string
*/
private function getUiLocale(AuthorizationInterface $authorization)
{
if (!method_exists($this->translator, 'getCatalogue') || !$authorization->hasQueryParam('ui_locales')) {
return;
}
$ui_locales = explode(' ', $authorization->getQueryParam('ui_locales'));
foreach ($ui_locales as $ui_locale) {
$catalogue = $this->translator->getCatalogue($ui_locale);
if (in_array('SpomkyLabsOAuth2Server', $catalogue->getDomains())) {
return $ui_locale;
}
}
}
示例5: log
/**
* Logs for missing translations.
*
* @param string $id
* @param string|null $domain
* @param string|null $locale
*/
private function log($id, $domain, $locale)
{
if (null === $domain) {
$domain = 'messages';
}
$id = (string) $id;
$catalogue = $this->translator->getCatalogue($locale);
if ($catalogue->defines($id, $domain)) {
return;
}
if ($catalogue->has($id, $domain)) {
$this->logger->debug('Translation use fallback catalogue.', array('id' => $id, 'domain' => $domain, 'locale' => $catalogue->getLocale()));
} else {
$this->logger->warning('Translation not found.', array('id' => $id, 'domain' => $domain, 'locale' => $catalogue->getLocale()));
}
}
示例6: getCatalogue
/**
* {@inheritdoc}
*/
public function getCatalogue($locale = null)
{
return $this->translator->getCatalogue($locale);
}
示例7: getCatalogue
/**
* Returns the message catalogue
*
* @param string $locale
*
* @return MessageCatalogueInterface
*/
protected function getCatalogue(string $locale) : MessageCatalogueInterface
{
return $this->translator->getCatalogue($locale);
}
示例8: getProgress
/**
* Return the number of translated messages
*
* @param string $locale
*
* @return int
*/
protected function getProgress($locale)
{
$catalogue = $this->translator->getCatalogue($locale);
return count($catalogue->all(), COUNT_RECURSIVE);
}