Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: Restore XLIFF translation fallback #1094

Merged
merged 2 commits into from Nov 11, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 19 additions & 8 deletions Neos.Flow/Classes/I18n/Xliff/Service/XliffFileProvider.php
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,30 @@ public function initializeObject()
*/
public function getMergedFileData($fileId, Locale $locale): array
{
if (!isset($this->files[$fileId][$locale->getLanguage()])) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm feels wrong to me to rely on the magic __toString() method, maybe add a getIdentifier or getLocaleIdentifier method and use that instead? __toString() could do that same then of course..

but maybe that's just me..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say a getIdentifier() method in \Neos\Flow\I18n\Locale is generally a good thing, but it's also a medium change to Flow if you consequently replace each Locale string cast with the new method. This is just a humble bugfix ;)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, seems like it's used a bunch of other places in the code so guess someone meant to use that way.. nvm then

if (!isset($this->files[$fileId][(string)$locale])) {
$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);
// Walk locale chain in reverse, so that translations higher in the chain overwrite fallback translations
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][(string)$locale] = $parsedData;
$this->cache->set('translationFiles', $this->files);
}

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

/**
Expand Down