Search code examples
javavaadinvaadin-flow

Localize page title in Vaadin


How can I localize page titles in Vaadin? I tried the following annotation but it didn't work:

@Route(URL)
@PageTitle("${user.account}")
@RolesAllowed({"ADMIN", "EMPLOYEE"})
public class AccountEditorView extends VerticalLayout {

The page title was not resolved but literally "${user.account}" instead of its value from the i18n message source.

Is there an annotation based way or do I have to implement HasDynamicTitle?


Solution

  • The @PageTitle is indeed more static in nature. For localisation it's best to implement the HasDynamicTitle interface. Do note that you can use only one of them in a class, not both.

    The Vaadin 24 documentation example of using HasDynamicTitle can be found here: https://vaadin.com/docs/latest/routing/page-titles#setting-the-page-title-dynamically