Skip to content

Fix parameter %resource% for translation#1089

Merged
Rafikooo merged 1 commit intoSylius:1.14from
michalkaczmarek-bitbag:feature/make-it-possible-to-translate-only-key-resource-in-flash-message
Dec 10, 2025
Merged

Fix parameter %resource% for translation#1089
Rafikooo merged 1 commit intoSylius:1.14from
michalkaczmarek-bitbag:feature/make-it-possible-to-translate-only-key-resource-in-flash-message

Conversation

@michalkaczmarek-bitbag
Copy link
Copy Markdown
Contributor

@michalkaczmarek-bitbag michalkaczmarek-bitbag commented Nov 10, 2025

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Related tickets #1062
License MIT

de_DE
Screenshot from 2025-11-27 22-22-07

fr_FR
Screenshot from 2025-11-27 22-23-33

pl_PL
Screenshot from 2025-11-27 22-24-22

@michalkaczmarek-bitbag michalkaczmarek-bitbag force-pushed the feature/make-it-possible-to-translate-only-key-resource-in-flash-message branch from 714d06b to 6484b00 Compare November 10, 2025 13:34
Copy link
Copy Markdown
Contributor

@Rafikooo Rafikooo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest extracting a dedicated private method, something like this:

  private function getParametersWithName(MetadataInterface $metadata, string $actionName): array
  {
      if (stripos($actionName, 'bulk') !== false) {
          $resourceName = $metadata->getPluralName();
          $fallback = ucfirst($resourceName);

          return ['%resources%' => $this->translateResourceName($resourceName, $fallback)];
      }

      $resourceName = $metadata->getName();
      $fallback = ucfirst($metadata->getHumanizedName());

      return ['%resource%' => $this->translateResourceName($resourceName, $fallback)];
  }

  private function translateResourceName(string $resourceName, string $fallback): string
  {
      $snakeCaseName = $this->convertToSnakeCase($resourceName);
      $translationKey = sprintf('%s%s', self::UI_TRANSLATION_PREFIX, $snakeCaseName);
      $translated = $this->translator->trans($translationKey, [], 'messages');

      return $translated === $translationKey ? $fallback : $translated;
  }

And I’d suggest adding a photo to the PR description

@michalkaczmarek-bitbag michalkaczmarek-bitbag force-pushed the feature/make-it-possible-to-translate-only-key-resource-in-flash-message branch from 6484b00 to 7257652 Compare November 27, 2025 21:29
@Rafikooo Rafikooo force-pushed the feature/make-it-possible-to-translate-only-key-resource-in-flash-message branch from 7257652 to 00ed218 Compare December 9, 2025 20:32
@Rafikooo Rafikooo merged commit fc43d68 into Sylius:1.14 Dec 10, 2025
13 checks passed
NoResponseMate added a commit that referenced this pull request Feb 9, 2026
| Q               | A
| --------------- | -----
| Bug fix?        | no
| New feature?    | yes
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | 
| License         | MIT

This improves the feature added in
#1089
It also adds the same feature in the new FlashHelper.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Idea: Make it possible to translate only the key of the resource in flash message

2 participants