本文整理汇总了PHP中Symfony\Component\Translation\Translator::__construct方法的典型用法代码示例。如果您正苦于以下问题:PHP Translator::__construct方法的具体用法?PHP Translator::__construct怎么用?PHP Translator::__construct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Translation\Translator
的用法示例。
在下文中一共展示了Translator::__construct方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* 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: __construct
/**
* @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: __construct
public function __construct($config = [])
{
foreach ($config as $name => $value) {
$this->{$name} = $value;
}
parent::__construct($this->defaultLocale, null, $this->cacheDir, $this->debug);
$this->init();
}
示例4: __construct
public function __construct(ServiceContainer $service, $locale)
{
parent::__construct($locale);
$this->service = $service;
$dispatcher = $service->getDispatcher();
$dispatcher->addSubscriber($this);
$this->domainStack = new Stack();
}
示例5: __construct
/**
* @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: __construct
/**
* @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);
}
示例7: __construct
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: __construct
/**
* @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: __construct
/**
* 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: __construct
/**
* 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: __construct
/**
* 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: __construct
public function __construct(Container $app, MessageSelector $selector)
{
$this->app = $app;
// TODO implementar o cache_dir e o debug
parent::__construct(null, $selector);
}
示例13: __construct
public function __construct(Application $app, MessageSelector $selector)
{
$this->app = $app;
parent::__construct(null, $selector);
}
示例14: __construct
public function __construct(array $config)
{
$this->config = $config;
parent::__construct($GLOBALS['TL_LANGUAGE']);
$this->setFallbackLocales(array('en'));
}
示例15: __construct
public function __construct(Application $app, MessageSelector $selector, $cacheDir = null, $debug = false)
{
$this->app = $app;
parent::__construct(null, $selector, $cacheDir, $debug);
}