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

Load i18n messages from third-party libraries #425

Open
rygel opened this issue May 16, 2018 · 2 comments
Open

Load i18n messages from third-party libraries #425

rygel opened this issue May 16, 2018 · 2 comments

Comments

@rygel
Copy link
Member

rygel commented May 16, 2018

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.

@decebals
Copy link
Member

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

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.

@rygel
Copy link
Member Author

rygel commented Jun 2, 2018

Thank you for your answer. I'm busy at the moment, but I will look into your suggestion.

rygel added a commit to rygel/pippo that referenced this issue Oct 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants