Skip to content

Commit

Permalink
BUGFIX: Restore XLIFF translation fallback
Browse files Browse the repository at this point in the history
This modification fixes the translation fallback mechanism and the ability to read regionalized language variants.

Issues fixed:

* Translation fallback did not work. `Neos.Flow.i18n.fallbackRule.order` was ignored when looking for XLIFF files
* When using a regional `Neos.Flow.i18n.defaultLocale` (e.g. `de_AT` for an Austrian version of German `de`), XLIFF files were never read from  a directory with the full `defaultLocale` name, but only from the base language directory. In the example, files in `Packages/Application/Vendor.Package/Resources/Private/Translations/de_AT` were never read, only `Packages/Application/Vendor.Package/Resources/Private/Translations/de`.
  • Loading branch information
fritjofbohm committed Oct 13, 2017
1 parent ebaee2f commit f9bcbcf
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions Neos.Flow/Classes/I18n/Xliff/Service/XliffFileProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Neos\Cache\Frontend\VariableFrontend;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\I18n;
use Neos\Flow\I18n\Locale;
use Neos\Flow\I18n\Xliff\Model\FileAdapter;
use Neos\Flow\I18n\Xliff\V12\XliffParser as V12XliffParser;
Expand All @@ -34,6 +35,12 @@ class XliffFileProvider
*/
protected $packageManager;

/**
* @Flow\Inject
* @var I18n\Service
*/
protected $localizationService;

/**
* @Flow\Inject
* @var XliffReader
Expand Down Expand Up @@ -87,26 +94,29 @@ public function initializeObject()
*/
public function getMergedFileData($fileId, Locale $locale): array
{
if (!isset($this->files[$fileId][$locale->getLanguage()])) {
if (!isset($this->files[$fileId][$locale->__toString()])) {
$parsedData = [
'fileIdentifier' => $fileId
];
foreach ($this->packageManager->getActivePackages() as $package) {
/** @var PackageInterface $package */
$translationPath = $package->getResourcesPath() . $this->xliffBasePath . $locale->getLanguage();
if (is_dir($translationPath)) {
$this->readDirectoryRecursively($translationPath, $parsedData, $fileId, $package->getPackageKey());
$localeChain = $this->localizationService->getLocaleChain($locale);
foreach (array_reverse($localeChain) as $localeChainItem) {
foreach ($this->packageManager->getActivePackages() as $package) {
/** @var PackageInterface $package */
$translationPath = $package->getResourcesPath() . $this->xliffBasePath . $localeChainItem;
if (is_dir($translationPath)) {
$this->readDirectoryRecursively($translationPath, $parsedData, $fileId, $package->getPackageKey());
}
}
}
$generalTranslationPath = FLOW_PATH_DATA . 'Translations';
if (is_dir($generalTranslationPath)) {
$this->readDirectoryRecursively(FLOW_PATH_DATA . 'Translations', $parsedData, $fileId);
}
$this->files[$fileId][$locale->getLanguage()] = $parsedData;
$this->files[$fileId][$locale->__toString()] = $parsedData;
$this->cache->set('translationFiles', $this->files);
}

return $this->files[$fileId][$locale->getLanguage()];
return $this->files[$fileId][$locale->__toString()];
}

/**
Expand Down

0 comments on commit f9bcbcf

Please sign in to comment.