Translation Service [message #1805673] |
Sat, 20 April 2019 14:56  |
Eclipse User |
|
|
|
Is there any way to use Translation Service in an e3 JavaFx OSGi application?
I am using pure OSGi and JavaFx. It is not an eclipse application, I just use the FX part with some plugins. I have been using NLS for localization but it only works with a restart.
When I came across this great blog post I wantted to use this for localization.
I had tried some examples but no hope. Any guide or suggessions? ( If possible a core code example will be appriciated)
Note: I can include any e4 plugin as long as it does not chance UI management.
|
|
|
Re: Translation Service [message #1805781 is a reply to message #1805673] |
Tue, 23 April 2019 21:17   |
Eclipse User |
|
|
|
I'm not sure i follow. Is this now e3 or pure OSGi? As many parts of e3 don't support language flipping it won't work there. What you definately need is the e4 injection container running but not the complete e4 framework
|
|
|
Re: Translation Service [message #1805816 is a reply to message #1805781] |
Wed, 24 April 2019 15:03   |
Eclipse User |
|
|
|
I mean project consists of pure OSGi bundles. Let me explain how I created my plugins. I used three types of plugins.
1- I created main project with "OSGi Application Project" wizard under JavaFX. It creates ".feature" and ".product" folders. This is an e3 application right? But my project is not a RCP application which uses eclipse UI. It has its own UI witout parts vs.
2- Then I created UI plugins with "OSGi Bundle Project" wizard under JavaFx.
3- Lastly all other non UI plugins with "Plug-in Project" wizard under Plugin Development.
I dont use maven or gradle. I manage dependencies manually and localy.
So which plugins are "e4 injection container" ?
org.eclipse.e4.core.di
org.eclipse.e4.core.context
org.eclipse.e4.core.di.annotations
org.eclipse.e4.core.services
Are these plugins enough to run it?
|
|
|
|
Re: Translation Service [message #1806869 is a reply to message #1806129] |
Thu, 16 May 2019 17:50   |
Eclipse User |
|
|
|
Thanks for the replies, I got it working with something like this:
in service :
@Component(immediate = true)
public class MainApplicationService implements IMainApplicationService {
private MainStage mainStage;
@Activate
void activate() {
BundleContext bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext();
IEclipseContext osgiContext = EclipseContextFactory.getServiceContext(bundleContext);
ContextInjectionFactory.setDefault(osgiContext);
this.mainStage = ContextInjectionFactory.make(MainStage.class, osgiContext);
this.mainStage.initComponents();
}
}
MainStage.java:
@Creatable
public class MainStage {
@Inject
private NamedMessageRegistry registry;
private void initComponents() {
Label label1 = new Label();
Label label2 = new Label();
Label label3 = new Label();
this.registry.register(label1::setText, m -> m.first_label_message);
this.registry.register(label2::setText, m -> m.second_label_message);
this.registry.register(label3::setText, m -> m.third_label_message);
}
}
However I cant inject ILocalChanceService in MainStage.java
I get InjectionException which says
no actual value was found for the argument "ILocaleChangeService".
How can I triger locale change ?
EDIT: After some searching, the code above creates bundle specific context which does not have Locale data.
Is there an application context or top level context in a osgi environment? How can I get it or is it the right way?
[Updated on: Fri, 17 May 2019 13:54] by Moderator Report message to a moderator
|
|
|
Re: Translation Service [message #1806934 is a reply to message #1806869] |
Sat, 18 May 2019 07:28   |
Eclipse User |
|
|
|
Ok, I found how to triger locale change. I just have to set the locale in the context :
public class MainStage {
// ...
@Inject
private IEclipseContext context;
//...
private void initComponents() {
//...
Button btn = new Button("Button");
btn.setOnAction(event -> {
context.set(TranslationService.LOCALE, Locale.ENGLISH);
});
}
//...
@Inject
@Optional
private void getNotified(@Named(TranslationService.LOCALE) Locale s) {
System.out.println("Injected via context: " + s);
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.03214 seconds