I'm trying to internationalize an OSGi application using the "OSGi way" but I haven't had progress. By OSGi way I mean, using the capabilities the framework provides for it. I have internationalized Java applications before but I'd like to know how to do it as an OSGi application.
I have created this simple demo [GitHub repo] which aims to create a bundle that will log a message once it is activated and another message once it is deactivated.
Project structure:
src
|- org.example.i18n
|- SimpleLoggingComponent // where the actual strings are
|- SimpleLogService
|- SimpleLogServiceImpl
META-INF
|- MANIFEST.MF
OSGI-INF
|- org.example.i18n.SimpleLoggingComponent
|- org.example.i18n.SimpleLogServiceImpl
build.properties
SimpleLoggingComponent source
@Component
public class SimpleLoggingComponent {
private SimpleLogService simpleLogService;
@Reference
public void bindLogger(SimpleLogService logService) {
this.simpleLogService = logService;
}
public void unbindLogger(SimpleLogService logService) {
this.simpleLogService = null;
}
@Activate
public void activate() {
if (simpleLogService != null) {
simpleLogService.log("Yee ha, I'm logging!"); // <-- need this message internationalized
}
}
@Deactivate
public void deactivate() {
if (simpleLogService != null) {
simpleLogService.log("Done, I'm finishing logging!"); // <-- need this message internationalized
}
}
}
For now, the strings are fixed in the code and I'd like to be able to internationalize these. Let's say, have English and Spanish languages supported.
Later I'm planning to add support for more languages by means of Fragment Bundles, so the solution should be ready to be extensible by this means.
I have read all these but I haven't found anything consistent that helps me.
- Using OSGi WAB as a Resource bundle inside a war
- JSP Spring internationalization using OSGi as service changing locale not working properly
- How to internationalize my eclipse Rcp application?
- Internationalization in RAP
- Eclipse RCP and Plugin Internationalization - Tutorial. Something is mentioned here about (...) OSGi resource bundles (...) but I'm not sure how to go about it.
- Eclipse Internationalization Part 2/4 – New Message Extension
Also, neither the OSGi Alliance Tutorial Archive nor the OSGi enRoute contains anything about it.
Environment:
- Equinox
- Eclipse version: 2019-03 (4.11.0), Build id: 20190314-1200 (download here)
- Target Platform (openhab.target)
- Eclipse Run Configuration
PS: I'm sure this is not a complicated task, it's just that I haven't found any useful (to me) documentation about it.