Skip to content

Commit

Permalink
Merge pull request #2 from camilleislasse/feature/#1-optimisation-fet…
Browse files Browse the repository at this point in the history
…ch-full-message-catalogue

optimisation cache
  • Loading branch information
sabrineferchichi authored Jan 20, 2025
2 parents e391745 + f939e34 commit 00a1a0d
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/Service/TranslationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function getTranslator(): TranslatorInterface
*/
public function getFullMessageCatalogue(bool $forceRevalidate = false): MessageCatalogue
{
$locales = Locales::getLocales();
$locales = array_keys($this->getAvailableLocales());

if ($forceRevalidate) {
$this->cache->delete(static::FULL_MESSAGE_CATALOGUE_CACHE_KEY);
Expand All @@ -167,27 +167,23 @@ public function getFullMessageCatalogue(bool $forceRevalidate = false): MessageC
static::FULL_MESSAGE_CATALOGUE_CACHE_KEY,
function (ItemInterface $item) use ($locales) {
$catalogue = new MessageCatalogue($this->getDefaultLocaleCode());
$availableLocales = $this->getAvailableLocales();
$localeCode = $this->translator->getLocale();

foreach ($locales as $key => $currentLocaleCode) {
foreach ($locales as $currentLocaleCode) {
$this->translator->setLocale($currentLocaleCode);
$localeMessageCatalogue = $this->translator->getCatalogue($currentLocaleCode);

foreach ($localeMessageCatalogue->all() as $domain => $translations) {
foreach ($translations as $id => $translation) {
if (!$catalogue->has($id, $domain)) {
$catalogue->set($id, '', $domain);
}
}
}

if (array_key_exists($currentLocaleCode, $availableLocales)) {
$localeCustomMessageCatalogue = $this->getCustomMessageCatalogue($currentLocaleCode);
foreach ($localeCustomMessageCatalogue->all() as $domain => $translations) {
foreach ($translations as $id => $translation) {
if (!$catalogue->has($id, $domain)) {
$catalogue->set($id, '', $domain);
}
$localeCustomMessageCatalogue = $this->getCustomMessageCatalogue($currentLocaleCode);
foreach ($localeCustomMessageCatalogue->all() as $domain => $translations) {
foreach ($translations as $id => $translation) {
if (!$catalogue->has($id, $domain)) {
$catalogue->set($id, '', $domain);
}
}
}
Expand Down

0 comments on commit 00a1a0d

Please sign in to comment.