Example #1
0
 /**
  * Detects the most suitable output format to use.
  *
  * @param string $domain
  * @throws \RuntimeException
  * @return string the output format
  */
 private function detectOutputFormat($currentDomain)
 {
     if (null !== $this->config->getOutputFormat()) {
         return $this->config->getOutputFormat();
     }
     // check if which translation files in which format exist
     $otherDomainFormat = $localeFormat = $otherLocaleFormat = null;
     foreach (FileUtils::findTranslationFiles($this->config->getTranslationsDir()) as $domain => $locales) {
         foreach ($locales as $locale => $fileData) {
             list($format, ) = $fileData;
             if ($currentDomain !== $domain) {
                 $otherDomainFormat = $format;
                 continue 2;
             }
             if ($this->config->getLocale() === $locale) {
                 $localeFormat = $format;
                 continue;
             }
             $otherLocaleFormat = $format;
         }
     }
     if (null !== $localeFormat) {
         return $localeFormat;
     }
     if (null !== $otherLocaleFormat) {
         return $otherLocaleFormat;
     }
     if (null !== $otherDomainFormat) {
         return $otherDomainFormat;
     }
     return $this->config->getDefaultOutputFormat();
 }
Example #2
0
 /**
  * @static
  * @param Config $config
  * @return ConfigBuilder
  */
 public static function fromConfig(Config $config)
 {
     $builder = new self();
     $builder->setTranslationsDir($config->getTranslationsDir());
     $builder->setLocale($config->getLocale());
     $builder->setIgnoredDomains($config->getIgnoredDomains());
     $builder->setDomains($config->getDomains());
     $builder->setOutputFormat($config->getOutputFormat());
     $builder->setDefaultOutputFormat($config->getDefaultOutputFormat());
     $builder->setScanDirs($config->getScanDirs());
     $builder->setExcludedDirs($config->getExcludedDirs());
     $builder->setExcludedNames($config->getExcludedNames());
     $builder->setEnabledExtractors($config->getEnabledExtractors());
     $builder->setLoadResources($config->getLoadResources());
     return $builder;
 }