use Symfony\Component\Translation\Loader\LoaderInterface;
use Symfony\Component\Translation\Exception\NotFoundResourceException;
+use Symfony\Component\Translation\Exception\InvalidArgumentException;
+use Symfony\Component\Translation\Exception\RuntimeException;
use Symfony\Component\Config\ConfigCacheInterface;
use Symfony\Component\Config\ConfigCacheFactoryInterface;
use Symfony\Component\Config\ConfigCacheFactory;
/**
* @var string
*/
- protected $locale;
+ private $locale;
/**
* @var array
* @param string|null $cacheDir The directory to use for the cache
* @param bool $debug Use cache in debug mode ?
*
- * @throws \InvalidArgumentException If a locale contains invalid characters
+ * @throws InvalidArgumentException If a locale contains invalid characters
*/
public function __construct($locale, MessageSelector $selector = null, $cacheDir = null, $debug = false)
{
* @param string $locale The locale
* @param string $domain The domain
*
- * @throws \InvalidArgumentException If the locale contains invalid characters
+ * @throws InvalidArgumentException If the locale contains invalid characters
*/
public function addResource($format, $resource, $locale, $domain = null)
{
return $this->locale;
}
- /**
- * Sets the fallback locale(s).
- *
- * @param string|array $locales The fallback locale(s)
- *
- * @throws \InvalidArgumentException If a locale contains invalid characters
- *
- * @deprecated since version 2.3, to be removed in 3.0. Use setFallbackLocales() instead
- */
- public function setFallbackLocale($locales)
- {
- @trigger_error('The '.__METHOD__.' method is deprecated since version 2.3 and will be removed in 3.0. Use the setFallbackLocales() method instead.', E_USER_DEPRECATED);
-
- $this->setFallbackLocales(is_array($locales) ? $locales : array($locales));
- }
-
/**
* Sets the fallback locales.
*
* @param array $locales The fallback locales
*
- * @throws \InvalidArgumentException If a locale contains invalid characters
+ * @throws InvalidArgumentException If a locale contains invalid characters
*/
public function setFallbackLocales(array $locales)
{
*/
public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null)
{
+ $parameters = array_merge(array(
+ '%count%' => $number,
+ ), $parameters);
+
if (null === $domain) {
$domain = 'messages';
}
return $this->loaders;
}
- /**
- * Collects all messages for the given locale.
- *
- * @param string|null $locale Locale of translations, by default is current locale
- *
- * @return array[array] indexed by catalog
- *
- * @deprecated since version 2.8, to be removed in 3.0. Use TranslatorBagInterface::getCatalogue() method instead.
- */
- public function getMessages($locale = null)
- {
- @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use TranslatorBagInterface::getCatalogue() method instead.', E_USER_DEPRECATED);
-
- $catalogue = $this->getCatalogue($locale);
- $messages = $catalogue->all();
- while ($catalogue = $catalogue->getFallbackCatalogue()) {
- $messages = array_replace_recursive($catalogue->all(), $messages);
- }
-
- return $messages;
- }
-
/**
* @param string $locale
*/
}
$this->assertValidLocale($locale);
- $self = $this; // required for PHP 5.3 where "$this" cannot be use()d in anonymous functions. Change in Symfony 3.0.
$cache = $this->getConfigCacheFactory()->cache($this->getCatalogueCachePath($locale),
- function (ConfigCacheInterface $cache) use ($self, $locale) {
- $self->dumpCatalogue($locale, $cache);
+ function (ConfigCacheInterface $cache) use ($locale) {
+ $this->dumpCatalogue($locale, $cache);
}
);
$this->catalogues[$locale] = include $cache->getPath();
}
- /**
- * This method is public because it needs to be callable from a closure in PHP 5.3. It should be made protected (or even private, if possible) in 3.0.
- *
- * @internal
- */
- public function dumpCatalogue($locale, ConfigCacheInterface $cache)
+ private function dumpCatalogue($locale, ConfigCacheInterface $cache)
{
$this->initializeCatalogue($locale);
$fallbackContent = $this->getFallbackContent($this->catalogues[$locale]);
if (isset($this->resources[$locale])) {
foreach ($this->resources[$locale] as $resource) {
if (!isset($this->loaders[$resource[0]])) {
- throw new \RuntimeException(sprintf('The "%s" translation loader is not registered.', $resource[0]));
+ throw new RuntimeException(sprintf('The "%s" translation loader is not registered.', $resource[0]));
}
$this->catalogues[$locale]->addCatalogue($this->loaders[$resource[0]]->load($resource[1], $locale, $resource[2]));
}
*
* @param string $locale Locale to tests
*
- * @throws \InvalidArgumentException If the locale contains invalid characters
+ * @throws InvalidArgumentException If the locale contains invalid characters
*/
protected function assertValidLocale($locale)
{
if (1 !== preg_match('/^[a-z0-9@_\\.\\-]*$/i', $locale)) {
- throw new \InvalidArgumentException(sprintf('Invalid "%s" locale.', $locale));
+ throw new InvalidArgumentException(sprintf('Invalid "%s" locale.', $locale));
}
}