Skip to content

Commit

Permalink
[BUGFIX] Optimize performance of source updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Goerz authored and ervaude committed Dec 19, 2018
1 parent 3615f33 commit 3af424d
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions Classes/Domain/Service/TranslationFileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,33 +355,28 @@ public function prepareXmlLanguageFiles($xmlFile)
}

/**
* For all configured languages we update the source of the label from the POST request.
* This is because it was changed in the default language which is the source of all
* other languages.
*
* So changes in "default" are reflected in an updated source of all other languages.
*
* @param array $postParam
*/
public function updateSourceInFiles(array $postParam)
{
$configuredLanguages = $this->l10nConfiguration->getAvailableL10nLanguages();
$translationFile = $this->translationFileFactory->findByPath($postParam['path']);
$translation = new Translation('', $postParam['key'], '', $postParam['target']);

foreach ($configuredLanguages as $language) {
if ($language !== 'default') {
$this->mergeLabelInAllLanguagesAsDefault($language, $postParam);
if ($language === 'default') {
continue;
}
}
}

/**
* @param string $language
* @param array $postParam
* @return void
*/
protected function mergeLabelInAllLanguagesAsDefault(string $language, array $postParam)
{
$translationFile = $this->translationFileFactory->findByPath($postParam['path']);
$l10nTranslationFile = $translationFile->getL10nTranslationFile($language);
foreach ($translationFile->getTranslations() as $translation) {
if ($l10nTranslationFile->hasOwnTranslation($translation)) {
$translation = new Translation('ignore this!', $postParam['key'], 'ignore this!', $postParam['target']);
$l10nTranslationFile->replaceTranslationSource($translation);
$this->translationFileWriterService->writeTranslationXlf($l10nTranslationFile);
}
$l10nTranslationFile = $translationFile->getL10nTranslationFile($language);
$l10nTranslationFile->replaceTranslationSource($translation);
$this->translationFileWriterService->writeTranslationXlf($l10nTranslationFile);
}
}
}

0 comments on commit 3af424d

Please sign in to comment.