Skip to content

Commit db21494

Browse files
minor #62790 [Translation] Perf: Keep catalogues if fallback locales have no change (rr-it)
This PR was merged into the 8.1 branch. Discussion ---------- [Translation] Perf: Keep catalogues if fallback locales have no change | Q | A | ------------- | --- | Branch? | 8.1 | Bug fix? | no | New feature? | no <!-- if yes, also update src/**/CHANGELOG.md --> | Deprecations? | no <!-- if yes, also update UPGRADE-*.md and src/**/CHANGELOG.md --> | Issues | Fix #... <!-- prefix each issue number with "Fix #"; no need to create an issue if none exists, explain below --> | License | MIT With this change a call to `Translator::setFallbackLocales()` will not clear the catalogues in case the current fallback locales are already equal to the newly to be set fallback locales. Any regeneration of catalogues is computational expensive. <!-- 🛠️ Replace this text with a concise explanation of your change: - What it does and why it's needed - A simple example of how it works (include PHP, YAML, etc.) - If it modifies existing behavior, include a before/after comparison Contributor guidelines: - ✅ Add tests and ensure they pass - 🐞 Bug fixes must target the **lowest maintained** branch where they apply https://symfony.com/releases#maintained-symfony-branches - ✨ New features and deprecations must target the **feature** branch and must add an entry to the changelog file of the patched component: https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - 🔒 Do not break backward compatibility: https://symfony.com/bc --> Commits ------- c216bb4 Perf: Keep catalogues if fallback locales have no change
2 parents 0406866 + c216bb4 commit db21494

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/Symfony/Component/Translation/Translator.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ public function getLocale(): string
145145
*/
146146
public function setFallbackLocales(array $locales): void
147147
{
148+
if ($this->getFallbackLocales() === $locales) {
149+
// No change in fallback locales:
150+
// Do not clear catalogues as regeneration of catalogues is computational expensive.
151+
return;
152+
}
153+
148154
// needed as the fallback locales are linked to the already loaded catalogues
149155
$this->catalogues = [];
150156

0 commit comments

Comments
 (0)