Skip to content
Snippets Groups Projects
Commit c7f71951 authored by Ben Martin's avatar Ben Martin Committed by Tim van Dijen
Browse files

A first attempt at storing generated po files in sorted order. This should...

A first attempt at storing generated po files in sorted order. This should hopefully minimize the number of changes that git sees when storing these files in a repo
parent 435ce928
No related branches found
No related tags found
No related merge requests found
......@@ -64,6 +64,26 @@ class UpdateTranslatableStringsCommand extends Command
);
}
/**
* Clone the entries from $iterator into the passed Translations object.
* It is expected that $iterator was made by getIterator() on Translations.
* This can be useful as the entries are cloned in the iterator order.
*
* @param Gettext\Translations $ret
* @param iterable $iterator
* @return $ret
*/
protected function cloneIteratorToTranslations(Translations $ret, iterable $iterator): Translations
{
while ($iterator->valid()) {
$ret->addOrMerge(
$iterator->current(),
Merge::TRANSLATIONS_THEIRS | Merge::COMMENTS_OURS | Merge::HEADERS_OURS | Merge::REFERENCES_OURS,
);
$iterator->next();
}
return $ret;
}
/**
* @param \Symfony\Component\Console\Input\InputInterface $input
......@@ -159,6 +179,16 @@ class UpdateTranslatableStringsCommand extends Command
Merge::TRANSLATIONS_THEIRS | Merge::COMMENTS_OURS | Merge::HEADERS_OURS | Merge::REFERENCES_OURS,
);
//
// Sort the translations in a predictable way
//
$iter = $merged->getIterator();
$iter->ksort();
$merged = $this->cloneIteratorToTranslations(
Translations::create($merged->getDomain(), $merged->getLanguage()),
$iter,
);
$poGenerator->generateFile($merged, $poFile->getPathName());
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment