Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » BundleTranslationProvider usage
BundleTranslationProvider usage [message #987048] Fri, 23 November 2012 08:06 Go to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Hi,

in Eclipse 3.x I used the approach to have one resource bundle per plugin instead of the one resource bundle per package like the "Externalize Strings" suggests. And I linked that resource bundle also in the MANIFEST.MF, so there is really only one resource bundle per plugin (for Eclipse resources and in code translation).

In Eclipse 4 there is the concept of the TranslationService. By using the BundleTranslationProvider and set the resource bundle to OSGI-INF/l10n this seems to be a similar approach or at least it could be used the same way. But there is one thing that seems to be strange looking at the BundleTranslationProvider.

I understand that the service needs to get the information out of which bundle it has to retrieve the translation. This is because the service is in application scope. Therefore the BundleTranslationProvider needs to search for the resource bundle on every translate() call. I'm not sure about the performance on searching files in the OSGi context, but IMHO this is odd. But I also don't have a solution on this.

Does the Eclipse Application Model also use the BundleTranslationProvider?

I could think of some solution to have a translation service per bundle, so you don't have to search the resource bundle everytime. But I'm not sure if this is a concept that is supported at the moment.

Of course I know that I can write my own service, but that would also be global. I can also keep the translations like before, but in fact I would need to write the same code for every plugin. I can also create a custom class that does nearly the same as the translation service and put it into the bundle context myself (which I am trying at the moment). I am just curious if this is also something that could be interesting in Eclipse 4 itself.

Greez,
Dirk

P.S. Sorry for the long text, just wanted to write down all my thoughts.
Re: BundleTranslationProvider usage [message #987053 is a reply to message #987048] Fri, 23 November 2012 08:17 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Am 23.11.12 09:06, schrieb Dirk Fauth:
> Hi,
>
> in Eclipse 3.x I used the approach to have one resource bundle per
> plugin instead of the one resource bundle per package like the
> "Externalize Strings" suggests. And I linked that resource bundle also
> in the MANIFEST.MF, so there is really only one resource bundle per
> plugin (for Eclipse resources and in code translation).
>
> In Eclipse 4 there is the concept of the TranslationService. By using
> the BundleTranslationProvider and set the resource bundle to
> OSGI-INF/l10n this seems to be a similar approach or at least it could
> be used the same way. But there is one thing that seems to be strange
> looking at the BundleTranslationProvider.
>
> I understand that the service needs to get the information out of which
> bundle it has to retrieve the translation. This is because the service
> is in application scope. Therefore the BundleTranslationProvider needs
> to search for the resource bundle on every translate() call. I'm not
> sure about the performance on searching files in the OSGi context, but
> IMHO this is odd. But I also don't have a solution on this.

well we could cache the Bundle we resolved from an URL - the problem is
we'd have to add listeners when the bundle is updated so that we remove
it from the cache.

>
> Does the Eclipse Application Model also use the BundleTranslationProvider?
>

Currently only the Application model makes use of this service - in
reality it's the renderers who call out for it by invokin
getLocalizedLabel and friends on the model

> I could think of some solution to have a translation service per bundle,
> so you don't have to search the resource bundle everytime. But I'm not
> sure if this is a concept that is supported at the moment.
>
> Of course I know that I can write my own service, but that would also be
> global. I can also keep the translations like before, but in fact I
> would need to write the same code for every plugin. I can also create a
> custom class that does nearly the same as the translation service and
> put it into the bundle context myself (which I am trying at the moment).
> I am just curious if this is also something that could be interesting in
> Eclipse 4 itself.
>

Did you ever looked at my @Translation stuff I wrote? It is similar to
how OSGi-NLS works but it works on instance variables instead of statics
and allows you to customize the translation message look up.

You can see it used inside the E4Application-ModelEditor like this:

class MyPart {
@Inject
@Translation
MyMessage messages;

@PostConstruct
void init(Composite parent) {
Label l = ...
l.setText(messages.mylabel);

}
}

The code is found in the tools.services bundle. This translation stuff
together with my resource pooling infrastructure (found in the same
bundle) this is what I think every e4 app should use.

Tom
Re: BundleTranslationProvider usage [message #987057 is a reply to message #987053] Fri, 23 November 2012 08:39 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Hi Tom,

this seems to be what I was looking for. Unfortunately I only found some presentation slides on this. Very interesting ones though. Because you worked on something I tried to solve myself the last days, create some general mechanism/service to load resources/messages per bundle without having to copy my code over and over for every bundle.

Is there some more documentation? The Message stuff seems to be an easy one, although I'm not sure how to integrate your service into my plugin (guess there is some xml in you slides, but without more detailed information it's hard to understand). Smile

Greez,
Dirk
Re: BundleTranslationProvider usage [message #987062 is a reply to message #987057] Fri, 23 November 2012 09:10 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Sorry there's fairly no documentation all I can do is point you to the
implementation and useages in code.

So here we go:

Implementation is found in org.eclipse.e4.tools.services[1]:
* Translation [2]: Is the annotation to mark objects

* TranslationObjectSupplier [3]: Teaches the DI-Engine the new
annotation "Translation" and uses IMessageFactoryService to create an
instance

* IMessageFactoryService [4]: Service interface used to create Message-
Object instances

* MessageFactoryServiceImpl [5]: Is a default implementation for
creating message instances and delegates to
PropertiesBundleTranslationProvider to do the filesystem lookup

* PropertiesBundleTranslationProvider [6]: Looks up the translations in
a local Properties file

* messagefactoryservice.xml [7]: Contributes the default
MessageFactoryServiceImpl into the OSGi-Service registry

* translationsupplier.xml [8]: Contributes the
TranslationObjectSupplier into the OSGi-Service registry

* Message [9]: Allows you to control the cacheing behavior of the
translations because we are working on instances and they can be
GC'ed if nobody references them anymore.

Usage is found in org.eclipse.e4.tools.emf.ui [10]:
* Messages [11]: Simply bean class with fields
* Messages.properties [12]: The translations
* ModelEditor [13]: Final user of all the magic from above ;-)

I will reply later on the resource loading stuff but in short it simply
uses the IContextFunction concept, together with DI @PreDestroy and
ref-counting.

Tom

[1]
http://git.eclipse.org/c/e4/org.eclipse.e4.tools.git/tree/bundles/org.eclipse.e4.tools.services

[2]
http://git.eclipse.org/c/e4/org.eclipse.e4.tools.git/tree/bundles/org.eclipse.e4.tools.services/src/org/eclipse/e4/tools/services/Translation.java

[3]
http://git.eclipse.org/c/e4/org.eclipse.e4.tools.git/tree/bundles/org.eclipse.e4.tools.services/src/org/eclipse/e4/tools/services/impl/TranslationObjectSupplier.java

[4]
http://git.eclipse.org/c/e4/org.eclipse.e4.tools.git/tree/bundles/org.eclipse.e4.tools.services/src/org/eclipse/e4/tools/services/IMessageFactoryService.java

[5]
http://git.eclipse.org/c/e4/org.eclipse.e4.tools.git/tree/bundles/org.eclipse.e4.tools.services/src/org/eclipse/e4/tools/services/impl/MessageFactoryServiceImpl.java

[6]
http://git.eclipse.org/c/e4/org.eclipse.e4.tools.git/tree/bundles/org.eclipse.e4.tools.services/src/org/eclipse/e4/tools/services/impl/PropertiesBundleTranslationProvider.java

[7]
http://git.eclipse.org/c/e4/org.eclipse.e4.tools.git/tree/bundles/org.eclipse.e4.tools.services/OSGI-INF/messagefactoryservice.xml

[8]
http://git.eclipse.org/c/e4/org.eclipse.e4.tools.git/tree/bundles/org.eclipse.e4.tools.services/OSGI-INF/translationsupplier.xml

[9]
http://git.eclipse.org/c/e4/org.eclipse.e4.tools.git/tree/bundles/org.eclipse.e4.tools.services/src/org/eclipse/e4/tools/services/Message.java

[10]
http://git.eclipse.org/c/e4/org.eclipse.e4.tools.git/tree/bundles/org.eclipse.e4.tools.emf.ui

[11]
http://git.eclipse.org/c/e4/org.eclipse.e4.tools.git/tree/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java

[12]
http://git.eclipse.org/c/e4/org.eclipse.e4.tools.git/tree/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties

[13]
http://git.eclipse.org/c/e4/org.eclipse.e4.tools.git/tree/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java




Am 23.11.12 09:39, schrieb Dirk Fauth:
> Hi Tom,
>
> this seems to be what I was looking for. Unfortunately I only found some
> presentation slides on this. Very interesting ones though. Because you
> worked on something I tried to solve myself the last days, create some
> general mechanism/service to load resources/messages per bundle without
> having to copy my code over and over for every bundle.
>
> Is there some more documentation? The Message stuff seems to be an easy
> one, although I'm not sure how to integrate your service into my plugin
> (guess there is some xml in you slides, but without more detailed
> information it's hard to understand). :)
>
> Greez,
> Dirk
Previous Topic:org.eclipse.ui 4 0.jar download
Next Topic:Active Selection in Child Context
Goto Forum:
  


Current Time: Thu Mar 28 15:07:30 GMT 2024

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

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

Back to the top