Example #1
0
 /**
  * @test
  */
 public function returnsNullWhenNoParentLocaleCouldBeFound()
 {
     foreach ($this->locales as $locale) {
         $this->localeCollection->addLocale($locale);
     }
     $this->assertNull($this->localeCollection->getParentLocaleOf(new \TYPO3\FLOW3\I18n\Locale('sv')));
     $this->assertNull($this->localeCollection->getParentLocaleOf($this->locales[0]));
 }
Example #2
0
 /**
  * Returns best-matching Locale object based on the template Locale object
  * provided as parameter. System default locale will be returned if no
  * successful matches were done.
  *
  * @param \TYPO3\FLOW3\I18n\Locale $locale The template Locale object
  * @return \TYPO3\FLOW3\I18n\Locale Best-matching existing Locale instance
  * @api
  */
 public function detectLocaleFromTemplateLocale(\TYPO3\FLOW3\I18n\Locale $locale)
 {
     $bestMatchingLocale = $this->localeCollection->findBestMatchingLocale($locale);
     if ($bestMatchingLocale !== NULL) {
         return $bestMatchingLocale;
     }
     return $this->localizationService->getConfiguration()->getDefaultLocale();
 }
Example #3
0
 /**
  * Finds all Locale objects representing locales available in the
  * FLOW3 installation. This is done by scanning all Private and Public
  * resource files of all active packages, in order to find localized files.
  *
  * Localized files have a locale identifier added before their extension
  * (or at the end of filename, if no extension exists). For example, a
  * localized file for foobar.png, can be foobar.en.png, fobar.en_GB.png, etc.
  *
  * Just one localized resource file causes the corresponding locale to be
  * regarded as available (installed, supported).
  *
  * Note: result of this method invocation is cached
  *
  * @return void
  */
 protected function generateAvailableLocalesCollectionByScanningFilesystem()
 {
     foreach ($this->packageManager->getActivePackages() as $activePackage) {
         $packageResourcesPath = $this->localeBasePath . $activePackage->getPackageKey() . '/';
         if (!is_dir($packageResourcesPath)) {
             continue;
         }
         $directoryIterator = new \RecursiveDirectoryIterator($packageResourcesPath, \RecursiveDirectoryIterator::UNIX_PATHS);
         $recursiveIteratorIterator = new \RecursiveIteratorIterator($directoryIterator, \RecursiveIteratorIterator::SELF_FIRST);
         foreach ($recursiveIteratorIterator as $fileOrDirectory) {
             if ($fileOrDirectory->isFile()) {
                 $localeIdentifier = Utility::extractLocaleTagFromFilename($fileOrDirectory->getFilename());
                 if ($localeIdentifier !== FALSE) {
                     $this->localeCollection->addLocale(new Locale($localeIdentifier));
                 }
             }
         }
     }
 }