Skip to content

Conversation

@dece
Copy link

@dece dece commented Oct 29, 2025

This is a reopening of PR 29.

I added two unit tests and a line in the readme to tell about the feature. I'm not used to testing in PHP yet so let me know if there is something I can improve.

Copying the original message below.


Currently, labels can only be a static string, a translated string without parameters, or a value retrieved from a property path. It would be nice to have a system for translated strings with parameters. My use case is that for some breadcrumb I would like to prepend something to a property, and/or surround a property with quotes (e.g. instead of rendering the dynamic value prop as prop, I would like Property : “prop”).

This PR implements this use case by allowing the property path given as label to resolve to a TranslatableMessage instead of a plain string. It respects the translationDomain setting except that false is not considered differently than null so that the default domain is used (indeed it would make no sense to disable translation on a TranslatableMessage).

This allows setting up a breadcrumb like so:

// The breadcrumb uses the breadcrumbLabel property of a Tier object.
const array TIER_BREADCRUMB = [
'label' => '$tier.breadcrumbLabel',
'route' => 'app_tier_detail',
'params' => ['id' => '$tier.id'],
'translationDomain' => null,
];

// The breadcrumbLabel property returns a TranslatableMessage instead of a plain string.
class Tier {
public function getBreadcrumbLabel(): TranslatableMessage {
return new TranslatableMessage('trans_str_with_params', ['%param%' => $this->anotherProperty]);
}
}

// The Route is not relevant here.
#[Route('/tiers/{id}', name: 'app_tier_detail')]
#[Breadcrumb(TIER_BREADCRUMB)]
public function myRoute(int $id) { /* … */ }

Let me know what you think!

@dece dece changed the title Support translatable message Support TranslatableMessage as a label value Oct 29, 2025
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.

1 participant