Neos\Flow\I18n\Service::getXliffFilenameAndPath PHP Method

getXliffFilenameAndPath() public method

Searching is done for the current locale if no $locale parameter is provided. The search is done according to the configured fallback rule. If parameter $strict is provided, searching is done only for the provided / current locale (without searching of files localized for more generic locales). If no localized version of file is found, $filepath is returned without any change.
See also: Configuration::setFallbackRule()
public getXliffFilenameAndPath ( string $path, string $sourceName, Locale $locale = null ) : array
$path string Base directory to the translation files
$sourceName string name of the translation source
$locale Locale Desired locale of XLIFF file
return array Path to the localized file (or $filename when no localized file was found) and the matched locale
    public function getXliffFilenameAndPath($path, $sourceName, Locale $locale = null)
    {
        if ($locale === null) {
            $locale = $this->configuration->getCurrentLocale();
        }
        foreach ($this->getLocaleChain($locale) as $localeIdentifier => $locale) {
            $possibleXliffFilename = Files::concatenatePaths([$path, $localeIdentifier, $sourceName . '.xlf']);
            if (file_exists($possibleXliffFilename)) {
                return [$possibleXliffFilename, $locale];
            }
        }
        return [false, $locale];
    }

Usage Example

 /**
  * Returns a XliffModel instance representing desired XLIFF file.
  *
  * Will return existing instance if a model for given $sourceName was already
  * requested before. Returns FALSE when $sourceName doesn't point to existing
  * file.
  *
  * @param string $packageKey Key of the package containing the source file
  * @param string $sourceName Relative path to existing CLDR file
  * @param I18n\Locale $locale Locale object
  * @return XliffModel New or existing instance
  * @throws I18n\Exception
  */
 protected function getModel($packageKey, $sourceName, I18n\Locale $locale)
 {
     $sourcePath = Files::concatenatePaths(['resource://' . $packageKey, $this->xliffBasePath]);
     list($sourcePath, $foundLocale) = $this->localizationService->getXliffFilenameAndPath($sourcePath, $sourceName, $locale);
     if ($sourcePath === false) {
         throw new I18n\Exception('No XLIFF file is available for ' . $packageKey . '::' . $sourceName . '::' . $locale . ' in the locale chain.', 1334759591);
     }
     if (isset($this->models[$sourcePath])) {
         return $this->models[$sourcePath];
     }
     return $this->models[$sourcePath] = new XliffModel($sourcePath, $foundLocale);
 }