Skip to content
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

chore: Reference contributor for Hilla translate method usage #288

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

MarcinVaadin
Copy link
Member

Fixes #232

Copy link

Artifact build on last commit: distributions.zip.
For MacOS users: there is a zip inside this zip and Finder unzips them both at once. Use unzip distributions.zip from Terminal or check solution for Archive Manager.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

@mgarciavaadin mgarciavaadin left a comment

Choose a reason for hiding this comment

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

Works for Hilla, good job!
I did not notice any change in Flow though, what should I expect?

@MarcinVaadin
Copy link
Member Author

MarcinVaadin commented Feb 3, 2025

I did not notice any change in Flow though, what should I expect?

With this update only vaadin-i18n.translations bundle properties are considered. Without that fix if you use getTranslation('server.port') spring application.properties will be opened which was wrong.

@mgarciavaadin
Copy link
Contributor

I did not notice any change in Flow though, what should I expect?

With this update only vaadin-i18n.translations bundle properties are considered. Without that fix if you use getTranslation('server.port') spring application.properties will be opened which was wrong.

Then I understood correctly and it is not working for Flow ;) . At least it still is showing the application properties file as options.

Screenshot 2025-02-03 at 14 17 09

ping @MarcinVaadin

Copy link
Contributor

@mgarciavaadin mgarciavaadin left a comment

Choose a reason for hiding this comment

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

In the Flow use case I still see all the application.properties options suggested if I click on a translate("server.port") translation.

@rodolforfq
Copy link

Any chance we could include the I18NProvider.translate method in the Flow inspections as well? Would be nice for all 3 different approaches to be equally hi-lighted:

  • Component.getTranslation() => already included in VaadinReferenceContributor class (renamed to FlowReferenceContributor on this PR)
  • UI.getTranslation() => inherits Component above
  • I18NProvider.translate() => doesn't work

I understand you may want to do this in a separate PR, just throwing the idea out there since a customer is interested.

@MarcinVaadin
Copy link
Member Author

Any chance we could include the I18NProvider.translate method in the Flow inspections as well?

Sure!

@MarcinVaadin
Copy link
Member Author

MarcinVaadin commented Feb 10, 2025

@rodolforfq you meant com.vaadin.flow.i18n.I18NProvider.getTranslation( ) ?

If so, it's interface and implementation might be custom, not only based on properties file...

@rodolforfq
Copy link

@MarcinVaadin you are right. In that case, it should be com.vaadin.flow.i18n.DefaultI18NProvider#getTranslation as it is the default implementation and it uses the properties file. If a user creates a custom implementation, it is most likely not going to be based on the properties file and as such, no hi-lightning should be expected either.

@rodolforfq
Copy link

I took a second look at this. You can't call the static method on DefaultI18NProvider as you can on the interface. It doesn't make much sense to add this to the plugin after all. The Component#getTraslation method seems to be the most straightforward way to use the localization feature.

While the static method on the I18NProvider interface is very useful for some specific cases (initializing an Enum with localized values, for example), it falls outside the scope of the framework itself. Please disregard my previous comments 🙇🏼‍♂️

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.

Update i18n references contributor
4 participants