-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[Feature] Prioritize default locale in TranslationLocaleProvider output #18365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughRefactors TranslationLocaleProvider::getDefinedLocalesCodes() to collect locale codes with a static, typed closure and move the configured default locale to the front of the returned array if present. Adds an upgrade note documenting this behavior. No public method signatures changed. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Caller as Consumer
participant Provider as TranslationLocaleProvider
participant Config as config/parameters
Caller->>Provider: getDefinedLocalesCodes()
Provider->>Provider: collect locale entities\nvia static typed closure\nbuild local $codes array
Provider->>Config: read configured default_locale
alt default locale present in $codes
Provider->>Provider: remove default from list
Provider->>Provider: unshift default to front
end
Provider-->>Caller: return reordered $codes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Poem
Pre-merge checks✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
❌ Preview Environment deleted from BunnyshellAvailable commands:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (4)
src/Sylius/Component/Core/Provider/TranslationLocaleProvider.php (4)
32-37: Avoid casting null locale codes to empty strings.If LocaleInterface::getCode() can be null, casting to string yields '', which may leak empty codes downstream. Filter null/empty codes explicitly.
Apply:
- $codes = array_map( - static function (LocaleInterface $locale): string { - return (string) $locale->getCode(); - }, - $locales, - ); + $codes = array_values(array_filter( + array_map( + static function (LocaleInterface $locale): ?string { + return $locale->getCode(); + }, + $locales, + ), + static fn (?string $code): bool => $code !== null && $code != '', + ));
39-44: Optional: simplify reordering into a single expression.A more declarative approach keeps the intent compact without changing behavior.
Apply:
- $default = $this->defaultLocaleCode; - if (false !== ($key = array_search($default, $codes, true))) { - unset($codes[$key]); - array_unshift($codes, $default); - } + $default = $this->defaultLocaleCode; + if (in_array($default, $codes, true)) { + $codes = array_merge([$default], array_values(array_diff($codes, [$default]))); + }
22-26: Mark promoted constructor properties as readonly.This service is immutable; readonly communicates intent and prevents accidental mutation.
Apply:
- private LocaleCollectionProviderInterface $localeRepository, - private string $defaultLocaleCode, + private readonly LocaleCollectionProviderInterface $localeRepository, + private readonly string $defaultLocaleCode,
28-29: Document the return shape as list.Native types can’t express array element types; a brief PHPDoc improves static analysis.
Apply:
- public function getDefinedLocalesCodes(): array + /** @return list<string> */ + public function getDefinedLocalesCodes(): array
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/Sylius/Component/Core/Provider/TranslationLocaleProvider.php(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{php,yaml,yml,xml,twig}
📄 CodeRabbit inference engine (AGENTS.md)
Use 4 spaces for indentation in PHP, YAML, XML, and Twig files
Files:
src/Sylius/Component/Core/Provider/TranslationLocaleProvider.php
**/*.php
📄 CodeRabbit inference engine (AGENTS.md)
**/*.php: Use modern PHP 8.2+ syntax and features
Declare strict_types=1 in all PHP files
Follow the Sylius Coding Standard
Do not use deprecated features from PHP, Symfony, or Sylius
Use final for all classes, except entities and repositories
Use readonly for immutable services and value objects
Add type declarations for all properties, arguments, and return values
Use camelCase for variables and method names
Use SCREAMING_SNAKE_CASE for constants
Use fast returns instead of unnecessary nesting
Use trailing commas in multi-line arrays and argument lists
Order array keys alphabetically where applicable
Use PHPDoc only when necessary (e.g., @var Collection)
Group class elements in order: constants, properties, constructor, public, protected, private methods
Group getter and setter methods for the same properties together
Suffix interfaces with Interface and traits with Trait
Use use statements for all non-global classes
Sort use imports alphabetically and group by type (classes, functions, constants)
Files:
src/Sylius/Component/Core/Provider/TranslationLocaleProvider.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Packages / Get matrix
- GitHub Check: Frontend / Get matrix
- GitHub Check: End-to-end tests (MariaDB) / Get matrix
- GitHub Check: End-to-end tests (PostgreSQL) / Get matrix
- GitHub Check: End-to-end tests (MySQL) / Get matrix
🔇 Additional comments (2)
src/Sylius/Component/Core/Provider/TranslationLocaleProvider.php (2)
32-37: LGTM: clean mapping to codes with a static, typed closure.The mapping reads well and aligns with PHP 8.2+ style (static closure, trailing comma).
39-44: LGTM: stable reordering to prioritize default locale while preserving the rest.Strict comparison in array_search and reindexing via array_unshift are correct here.
8b2d939 to
f950067
Compare
Rafikooo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be a good idea to include this behavioral change in the upgrade file.
1925c2b to
703aaf4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
UPGRADE-2.1.md (2)
5-7: Qualify behavior: only move default locale if presentAvoid overpromising “always”; the implementation moves it only when found. Suggested wording below.
-1. The `TranslationLocaleProvider` now ensures that the default locale (configured as `default_locale` in `config/parameters.yaml`) - is always placed at the beginning of the returned locales array. - Other locales remain in the same order as returned by the repository. +1. The `TranslationLocaleProvider` now places the default locale (configured as `default_locale` in `config/parameters.yaml`) + at the beginning of the returned locales array, if that locale is present among the available locales. + Other locales remain in the same order as returned by the repository.
3-3: Fix heading level per markdownlint (MD001)Change H3 to H2 to avoid skipping a level after the H1 section title.
-### Translations +## Translations
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
UPGRADE-2.1.md(1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
UPGRADE-2.1.md
3-3: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3
(MD001, heading-increment)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
- GitHub Check: End-to-end tests (MariaDB) / Non-JS, PHP 8.4, Symfony ^7.2, MariaDB 11.4.7, State Machine Adapter symfony_workflow
- GitHub Check: End-to-end tests (MariaDB) / Non-JS, PHP 8.2, Symfony ^6.4, MariaDB 10.11.13, State Machine Adapter winzou_state_machine
- GitHub Check: End-to-end tests (MySQL) / JS with Panther, PHP 8.3, Symfony ^7.2 (test_cached), MySQL 8.4, Twig ^3.3
- GitHub Check: End-to-end tests (MySQL) / JS with Chromedriver, PHP 8.2, Symfony ^6.4 (test_cached), MySQL 8.0, Twig ^3.3
- GitHub Check: End-to-end tests (MySQL) / JS with Panther, PHP 8.4, Symfony ^7.2 (test_cached), MySQL 8.4, Twig ^3.3
- GitHub Check: End-to-end tests (MySQL) / JS with Panther, PHP 8.2, Symfony ^6.4 (test_cached), MySQL 8.0, Twig ^3.3
- GitHub Check: End-to-end tests (MySQL) / JS with Chromedriver, PHP 8.4, Symfony ^7.2 (test_cached), MySQL 8.4, Twig ^3.3
- GitHub Check: End-to-end tests (MySQL) / Non-JS, PHP 8.4, Symfony ^7.2 (test_cached), MySQL 8.4, Twig ^3.3
- GitHub Check: End-to-end tests (MySQL) / JS with Chromedriver, PHP 8.3, Symfony ^7.2 (test_cached), MySQL 8.4, Twig ^3.3
- GitHub Check: End-to-end tests (MySQL) / Non-JS, PHP 8.3, Symfony ^7.2 (test_cached), MySQL 8.4, Twig ^3.3
- GitHub Check: End-to-end tests (MySQL) / Non-JS, PHP 8.2, Symfony ^6.4 (test_cached), MySQL 8.0, Twig ^3.3
- GitHub Check: End-to-end tests (PostgreSQL) / Non-JS, PHP 8.4, Symfony ^7.2, PostgreSQL 17.5
- GitHub Check: End-to-end tests (PostgreSQL) / Non-JS, PHP 8.2, Symfony ^6.4, PostgreSQL 15.13
- GitHub Check: Packages / PHP 8.2, Symfony ^6.4
- GitHub Check: Packages / PHP 8.3, Symfony ^7.2, ORM ^3.3
- GitHub Check: Packages / PHP 8.4, Symfony ^7.2
- GitHub Check: Frontend / NodeJS 24.x
src/Sylius/Component/Core/tests/Provider/TranslationLocaleProviderTest.php
Outdated
Show resolved
Hide resolved
src/Sylius/Component/Core/Provider/TranslationLocaleProvider.php
Outdated
Show resolved
Hide resolved
src/Sylius/Component/Core/Provider/TranslationLocaleProvider.php
Outdated
Show resolved
Hide resolved
src/Sylius/Component/Core/Provider/TranslationLocaleProvider.php
Outdated
Show resolved
Hide resolved
52d34e2 to
860dd9a
Compare
860dd9a to
d1f58dd
Compare
This PR ensures that the default locale code (defaultLocaleCode) is always placed at the beginning of the returned array.
Other locales remain in the same order as provided by the repository.
Default locale code is defined in: config/parameters.yaml
Added UnitTest for TranslationLocaleProvider.
Summary by CodeRabbit
Refactor
Documentation