Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » Translation Service
Translation Service [message #1805673] Sat, 20 April 2019 14:56 Go to next message
Kürşat Özer is currently offline Kürşat ÖzerFriend
Messages: 5
Registered: March 2019
Junior Member
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 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6505
Registered: July 2009
Senior Member
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 Go to previous messageGo to next message
Kürşat Özer is currently offline Kürşat ÖzerFriend
Messages: 5
Registered: March 2019
Junior Member
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 #1806129 is a reply to message #1805816] Fri, 03 May 2019 08:45 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6505
Registered: July 2009
Senior Member
on e3: What you created is an OSGi-Application, an e3 application is something using the using the compat-layer and SWT.
on bundles: yes that should be enough
Re: Translation Service [message #1806869 is a reply to message #1806129] Thu, 16 May 2019 17:50 Go to previous messageGo to next message
Kürşat Özer is currently offline Kürşat ÖzerFriend
Messages: 5
Registered: March 2019
Junior Member
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]

Report message to a moderator

Re: Translation Service [message #1806934 is a reply to message #1806869] Sat, 18 May 2019 07:28 Go to previous messageGo to next message
Kürşat Özer is currently offline Kürşat ÖzerFriend
Messages: 5
Registered: March 2019
Junior Member
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);
    }
}

Re: Translation Service [message #1806997 is a reply to message #1806934] Mon, 20 May 2019 20:49 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6505
Registered: July 2009
Senior Member
Right ILocalChanceService is a service provided by e4 framework and because you don't use e4 the service implementation is not possible
Previous Topic:Can't download e(fx)clipse
Next Topic:Splash screen
Goto Forum:
  


Current Time: Fri Sep 20 07:26:10 GMT 2019

Powered by FUDForum. Page generated in 0.01710 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top