__construct() public method

Constructor.
public __construct ( string $locale, Symfony\Component\Translation\MessageSelector $selector )
$locale string The locale
$selector Symfony\Component\Translation\MessageSelector The message selector for pluralization
示例#1
0
 /**
  * Override Symfony\Component\Translation\Translator to lazy load every catalogs from:
  *     - BackBee\Resources\translations
  *     - PATH_TO_REPOSITORY\Resources\translations
  *     - PATH_TO_CONTEXT_REPOSITORY\Resources\translations.
  *
  * @param BBApplication $application
  * @param string        $locale
  */
 public function __construct(BBApplication $application, $locale)
 {
     parent::__construct($locale);
     // retrieve default fallback from container and set it
     $fallback = $application->getContainer()->getParameter('translator.fallback');
     $this->setFallbackLocales([$fallback]);
     // xliff is recommended by Symfony so we register its loader as default one
     $this->addLoader('xliff', new XliffFileLoader());
     // define in which directory we should looking at to find xliff files
     $dirToLookingAt = array($application->getBBDir() . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'translations', $application->getRepository() . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'translations');
     if ($application->getRepository() !== $application->getBaseRepository()) {
         $dirToLookingAt[] = $application->getBaseRepository() . 'Resources' . DIRECTORY_SEPARATOR . 'translations';
     }
     // loop in every directory we should looking at and load catalog from file which match to the pattern
     foreach ($dirToLookingAt as $dir) {
         if (true === is_dir($dir)) {
             foreach (scandir($dir) as $filename) {
                 preg_match('/(.+)\\.(.+)\\.xlf$/', $filename, $matches);
                 if (0 < count($matches)) {
                     $this->addResource('xliff', $dir . DIRECTORY_SEPARATOR . $filename, $matches[2], $matches[1]);
                 }
             }
         }
     }
 }
示例#2
0
 /**
  * @param IUserLocaleResolver $localeResolver
  * @param MessageSelector $selector The message selector for pluralization
  * @param CatalogueCompiler $catalogueCompiler
  * @param FallbackResolver $fallbackResolver
  * @param IResourceLoader $loader
  */
 public function __construct(IUserLocaleResolver $localeResolver, MessageSelector $selector, CatalogueCompiler $catalogueCompiler, FallbackResolver $fallbackResolver, IResourceLoader $loader)
 {
     $this->localeResolver = $localeResolver;
     $this->catalogueCompiler = $catalogueCompiler;
     $this->fallbackResolver = $fallbackResolver;
     $this->translationsLoader = $loader;
     parent::__construct(NULL, $selector);
 }
示例#3
0
 public function __construct($config = [])
 {
     foreach ($config as $name => $value) {
         $this->{$name} = $value;
     }
     parent::__construct($this->defaultLocale, null, $this->cacheDir, $this->debug);
     $this->init();
 }
示例#4
0
 public function __construct(ServiceContainer $service, $locale)
 {
     parent::__construct($locale);
     $this->service = $service;
     $dispatcher = $service->getDispatcher();
     $dispatcher->addSubscriber($this);
     $this->domainStack = new Stack();
 }
示例#5
0
 /**
  * @param ContainerInterface $container
  */
 public function __construct(ContainerInterface $container)
 {
     $this->container = $container;
     // Allow singleton style calls once intanciated.
     // For this to work, the Translator service has to be instanciated very early. This is done manually
     // in TheliaHttpKernel, by calling $this->container->get('thelia.translator');
     parent::__construct(null);
     self::$instance = $this;
 }
示例#6
0
 /**
  * @param IUserLocaleResolver $localeResolver
  * @param MessageSelector $selector The message selector for pluralization
  * @param CatalogueCompiler $catalogueCompiler
  * @param FallbackResolver $fallbackResolver
  * @param IResourceLoader $loader
  */
 public function __construct(IUserLocaleResolver $localeResolver, MessageSelector $selector, CatalogueCompiler $catalogueCompiler, FallbackResolver $fallbackResolver, IResourceLoader $loader, ILogger $tracyLogger = null, LoggerInterface $psrLogger = null)
 {
     $this->localeResolver = $localeResolver;
     $this->catalogueCompiler = $catalogueCompiler;
     $this->fallbackResolver = $fallbackResolver;
     $this->translationsLoader = $loader;
     $this->logger = $psrLogger ?: $tracyLogger;
     parent::__construct(NULL, $selector);
 }
 public function __construct($config = array())
 {
     // @TODO: needs to be more configurable
     parent::__construct($config['fallback']);
     $this->addLoader('xlf', new XliffFileLoader());
     foreach ($config['resources'] as $resource) {
         extract($resource);
         $this->addResource($format, $resource, $locale, $domain);
     }
 }
示例#8
0
 /**
  * @param TranslatorLoaderProviderInterface $loaderProvider
  * @param TranslatorResourceProviderInterface $resourceProvider
  * @param MessageSelector $messageSelector
  * @param string $locale
  * @param array $options
  */
 public function __construct(TranslatorLoaderProviderInterface $loaderProvider, TranslatorResourceProviderInterface $resourceProvider, MessageSelector $messageSelector, $locale, array $options = [])
 {
     $this->assertOptionsAreKnown($options);
     $this->loaderProvider = $loaderProvider;
     $this->resourceProvider = $resourceProvider;
     $this->options = array_merge($this->options, $options);
     if (null !== $this->options['cache_dir'] && $this->options['debug']) {
         $this->addResources();
     }
     parent::__construct($locale, $messageSelector, $this->options['cache_dir'], $this->options['debug']);
 }
示例#9
0
 /**
  * Constructor.
  *
  * Available options:
  *
  *   * cache_dir: The cache directory (or null to disable caching)
  *   * debug:     Whether to enable debugging or not (false by default)
  *
  * @param ContainerInterface $container A ContainerInterface instance
  * @param MessageSelector    $selector  The message selector for pluralization
  * @param array              $loaderIds An array of loader Ids
  * @param array              $options   An array of options
  *
  * @throws \InvalidArgumentException
  */
 public function __construct(ContainerInterface $container, MessageSelector $selector, $loaderIds = array(), array $options = array())
 {
     $this->container = $container;
     $this->loaderIds = $loaderIds;
     // check option names
     if ($diff = array_diff(array_keys($options), array_keys($this->options))) {
         throw new \InvalidArgumentException(sprintf('The Translator does not support the following options: \'%s\'.', implode('\', \'', $diff)));
     }
     $this->options = array_merge($this->options, $options);
     parent::__construct(null, $selector);
 }
示例#10
0
 /**
  * Constructor.
  *
  * Available options:
  *
  *   * cache_dir: The cache directory (or null to disable caching)
  *   * debug:     Whether to enable debugging or not (false by default)
  *
  * @param ContainerInterface $container A ContainerInterface instance
  * @param MessageSelector    $selector  The message selector for pluralization
  * @param array              $options   An array of options
  * @param Session            $session   A Session instance
  */
 public function __construct(ContainerInterface $container, MessageSelector $selector, array $options = array(), Session $session = null)
 {
     parent::__construct(null, $selector);
     $this->session = $session;
     $this->container = $container;
     $this->options = array('cache_dir' => null, 'debug' => false);
     // check option names
     if ($diff = array_diff(array_keys($options), array_keys($this->options))) {
         throw new \InvalidArgumentException(sprintf('The Router does not support the following options: \'%s\'.', implode('\', \'', $diff)));
     }
     $this->options = array_merge($this->options, $options);
 }
示例#11
0
 /**
  * Constructor.
  *
  * Available options:
  *
  *   * cache_dir: The cache directory (or null to disable caching)
  *   * debug:     Whether to enable debugging or not (false by default)
  *   * resource_files: List of translation resources available grouped by locale.
  *
  * @param ContainerInterface $container A ContainerInterface instance
  * @param MessageSelector    $selector  The message selector for pluralization
  * @param array              $loaderIds An array of loader Ids
  * @param array              $options   An array of options
  *
  * @throws \InvalidArgumentException
  */
 public function __construct(ContainerInterface $container, MessageSelector $selector, $loaderIds = array(), array $options = array())
 {
     $this->container = $container;
     $this->loaderIds = $loaderIds;
     // check option names
     if ($diff = array_diff(array_keys($options), array_keys($this->options))) {
         throw new \InvalidArgumentException(sprintf('The Translator does not support the following options: \'%s\'.', implode('\', \'', $diff)));
     }
     $this->options = array_merge($this->options, $options);
     $this->resourceLocales = array_keys($this->options['resource_files']);
     if (null !== $this->options['cache_dir'] && $this->options['debug']) {
         $this->loadResources();
     }
     parent::__construct($container->getParameter('kernel.default_locale'), $selector, $this->options['cache_dir'], $this->options['debug']);
 }
示例#12
0
 public function __construct(Container $app, MessageSelector $selector)
 {
     $this->app = $app;
     // TODO implementar o cache_dir e o debug
     parent::__construct(null, $selector);
 }
示例#13
0
 public function __construct(Application $app, MessageSelector $selector)
 {
     $this->app = $app;
     parent::__construct(null, $selector);
 }
示例#14
0
 public function __construct(Container $app, MessageSelector $selector)
 {
     $this->app = $app;
     parent::__construct(null, $selector);
 }
 public function __construct(array $config)
 {
     $this->config = $config;
     parent::__construct($GLOBALS['TL_LANGUAGE']);
     $this->setFallbackLocales(array('en'));
 }
示例#16
0
 public function __construct(Application $app, MessageSelector $selector, $cacheDir = null, $debug = false)
 {
     $this->app = $app;
     parent::__construct(null, $selector, $cacheDir, $debug);
 }