You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am currently investigating and thinking of, how to add translations to Pippo via third-party libraries. In my use case, I have my own library pippo-contact-route and it should include some strings (default error messages) in multiple languages. As far as I understand all translations are read when creating the Application instance and the default strings are read from the hard-coded default locations. Then the strings in the application resources folder are read. However, nothing is read when packages are discovered via the ServiceLocator.
At the moment I am exploring two approaches:
Automatic discovery and loading of translations via the ServiceLocator. This means all third-party libraries must have a class, which inherits a special interface.
Adding a method to the application class to add translations during runtime. I am not sure how this affects the template engines, because they include a translation mechanism and get the Messages object injected at creation, i.e. before the Application object is ready.
I appreciate any comments and suggestions. Once I have a prototype which is not too invasive of the current design I will create a test and PR.
The text was updated successfully, but these errors were encountered:
First of all, sorry for delay.
I think that your idea is good because in this mode you can come with encapsulated components in a Pippo application. For the moment I don't know the correct way to implement this feature.
You described two approaches and I come with another possible approach
use ClasspathUtils#getResources() instead of ClasspathUtils#locateOnClasspath in Messages#loadMessages(String fileOrUrl)
We have multiple possibilities to implement this feature but the tricky part is to pick the most non intrusive and simple.
We can add a new X method in Messages (and a helper in Application that calls messages.X) and to call Messages#loadRegisteredMessageResources lazy when someone call messages.get()). In this mode we can use ApplicationInitializer to inject new messages locations via ServiceLoader META-INF/services/.
In all approaches a problem is related to overriding the initial message text.
For example, the third party library with name X comes with a builtin value for a key but I want to have the possibility to override the message text using my app's conf/messages.properties file.
I am currently investigating and thinking of, how to add translations to Pippo via third-party libraries. In my use case, I have my own library pippo-contact-route and it should include some strings (default error messages) in multiple languages. As far as I understand all translations are read when creating the Application instance and the default strings are read from the hard-coded default locations. Then the strings in the application resources folder are read. However, nothing is read when packages are discovered via the ServiceLocator.
At the moment I am exploring two approaches:
I appreciate any comments and suggestions. Once I have a prototype which is not too invasive of the current design I will create a test and PR.
The text was updated successfully, but these errors were encountered: