Symfony\Component\Translation\Translator::__construct PHP Метод

__construct() публичный Метод

Constructor.
public __construct ( string $locale, Symfony\Component\Translation\MessageSelector $selector )
$locale string The locale
$selector Symfony\Component\Translation\MessageSelector The message selector for pluralization
    public function __construct($locale, MessageSelector $selector)
    {
        $this->locale = $locale;
        $this->selector = $selector;
        $this->loaders = array();
        $this->resources = array();
        $this->catalogues = array();
    }

Usage Example

Пример #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]);
                 }
             }
         }
     }
 }
All Usage Examples Of Symfony\Component\Translation\Translator::__construct