Skip to content

Commit c7f7195

Browse files
monkeyiqtvdijen
authored andcommitted
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
1 parent 435ce92 commit c7f7195

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

src/SimpleSAML/Command/UpdateTranslatableStringsCommand.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,26 @@ protected function configure(): void
6464
);
6565
}
6666

67+
/**
68+
* Clone the entries from $iterator into the passed Translations object.
69+
* It is expected that $iterator was made by getIterator() on Translations.
70+
* This can be useful as the entries are cloned in the iterator order.
71+
*
72+
* @param Gettext\Translations $ret
73+
* @param iterable $iterator
74+
* @return $ret
75+
*/
76+
protected function cloneIteratorToTranslations(Translations $ret, iterable $iterator): Translations
77+
{
78+
while ($iterator->valid()) {
79+
$ret->addOrMerge(
80+
$iterator->current(),
81+
Merge::TRANSLATIONS_THEIRS | Merge::COMMENTS_OURS | Merge::HEADERS_OURS | Merge::REFERENCES_OURS,
82+
);
83+
$iterator->next();
84+
}
85+
return $ret;
86+
}
6787

6888
/**
6989
* @param \Symfony\Component\Console\Input\InputInterface $input
@@ -159,6 +179,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
159179
Merge::TRANSLATIONS_THEIRS | Merge::COMMENTS_OURS | Merge::HEADERS_OURS | Merge::REFERENCES_OURS,
160180
);
161181

182+
//
183+
// Sort the translations in a predictable way
184+
//
185+
$iter = $merged->getIterator();
186+
$iter->ksort();
187+
$merged = $this->cloneIteratorToTranslations(
188+
Translations::create($merged->getDomain(), $merged->getLanguage()),
189+
$iter,
190+
);
191+
162192
$poGenerator->generateFile($merged, $poFile->getPathName());
163193
}
164194
}

0 commit comments

Comments
 (0)