This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 428427 - Refactor TranslationService and BundleTranslationProvider to be extensible
Summary: Refactor TranslationService and BundleTranslationProvider to be extensible
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Runtime (show other bugs)
Version: 4.4   Edit
Hardware: PC Windows 7
: P3 enhancement (vote)
Target Milestone: 4.4 M6   Edit
Assignee: Paul Webster CLA
QA Contact:
URL:
Whiteboard:
Keywords: noteworthy
Depends on:
Blocks:
 
Reported: 2014-02-18 08:37 EST by Dirk Fauth CLA
Modified: 2014-03-05 07:33 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Fauth CLA 2014-02-18 08:37:10 EST
With the following question on stackoverflow, I started looking into the possiblities on using a custom TranslationService implementation.

http://stackoverflow.com/questions/21776496/eclipse-rcp-getting-resourcebundles-using-custom-resourcebundle-control

IMHO the code to retrieve the bundle now also exists in the ResourceBundleHelper I contributed for the new message extension. So the logic could be reused.

The getResourceString() method is something that every implementation will need, as it deals with the leading % which is a pre-requisite for translations in the application model. Therefore I would transfer it to the TranslationService with protected visibility, so custom TranslationService implementations could simply use it instead of copying the code.

As a third fact I would like to get the BundleLocalization injected rather than getting it directly via ServicesActivator.

With these modifications it would be simply to create a custom TranslationService. And it would also be enable people to easily use ResourceBundles that are retrieved from different locations than the OSGi ResourceBundle, e.g. as use case on stackoverflow, retrieving the ResourceBundle from another server by using a different ResourceBundle.Control. 

I asked on the e4 mailing list about opinions on that, but there was no response yet. Having the API freeze of Luna M6 in mind, I wanted to create the ticket and provide a patch via Gerrit.
Comment 1 Paul Webster CLA 2014-02-18 19:10:39 EST
See https://git.eclipse.org/r/#/c/22159/
Comment 3 Paul Webster CLA 2014-02-20 10:20:38 EST
Dirk, can you confirm and then resolve the bug?

PW
Comment 4 Dirk Fauth CLA 2014-02-21 02:54:15 EST
Hi Paul,

I pulled the current origin/master and tested with my examples on GitHub. Everything seems to work fine. If you want to do some checks too, here is the link to my GitHub repo: https://github.com/fipro78

But I still get the following warning:
IMessageFactoryService.getMessageInstance(Locale, Class<M>, ResourceBundleProvider) has non-API parameter type ResourceBundleProvider

Checking the MANIFEST in org.eclipse.e4.core.services I see that the exported package org.eclipse.e4.core.services.translation is configured as x-internal:=true

Is that intended? I would have thought that the core.services.translation package should have the same visibility than core.services.nls
Comment 5 Thomas Schindl CLA 2014-02-21 02:59:02 EST
+1 on making the translation package API with Luna
Comment 6 Lars Vogel CLA 2014-02-21 04:00:09 EST
(In reply to Thomas Schindl from comment #5)
> +1 on making the translation package API with Luna

I like the current policy to release only something as API which has been around for a while, the translation service feels a bit to new for me to be released as API for Luna. Also it look like Dirk is still actively improving it, maybe better to wait for Luna+1?
Comment 7 Thomas Schindl CLA 2014-02-21 04:01:25 EST
You are mixing things up - Translation-Service is available since the inception of Eclipse 4! The new stuff is the NLS-Package!
Comment 8 Lars Vogel CLA 2014-02-21 04:04:33 EST
(In reply to Thomas Schindl from comment #7)
> You are mixing things up - Translation-Service is available since the
> inception of Eclipse 4! The new stuff is the NLS-Package!

Thanks for the clarification but didn't we just change the Translation Service in this bug? I did not not at the code change, so I might be wrong.
Comment 9 Thomas Schindl CLA 2014-02-21 04:07:18 EST
we modified it but in an API compliant way - the API of the service has not been modified but we moved some code from internal to external so that people can reuse things when implementing a custom version
Comment 10 Thomas Schindl CLA 2014-02-21 04:09:21 EST
what refactored is the default implementation we are providing!
Comment 11 Lars Vogel CLA 2014-02-21 04:15:00 EST
(In reply to Thomas Schindl from comment #10)
> what refactored is the default implementation we are providing!

Thanks again for the clarification, +1 for the API release in this case from me too.
Comment 12 Lars Vogel CLA 2014-02-21 07:01:25 EST
In Build id: N20140219-2000 I see the following error in the Error Log

java.lang.StringIndexOutOfBoundsException: String index out of range: -1
	at java.lang.String.substring(String.java:1918)
	at org.eclipse.e4.core.internal.services.ResourceBundleHelper.getResourceBundleForUri(ResourceBundleHelper.java:132)
	at org.eclipse.e4.core.internal.services.BundleTranslationProvider.translate(BundleTranslationProvider.java:29)
	at org.eclipse.e4.ui.model.LocalizationHelper.getLocalized(LocalizationHelper.java:134)
	at org.eclipse.ui.internal.quickaccess.ViewElement.getLabel(ViewElement.java:100)
	at org.eclipse.ui.internal.quickaccess.QuickAccessElement.match(QuickAccessElement.java:92)
	at org.eclipse.ui.internal.quickaccess.QuickAccessContents.computeMatchingEntries(QuickAccessContents.java:341)
	at org.eclipse.ui.internal.quickaccess.QuickAccessContents.refresh(QuickAccessContents.java:128)
	at org.eclipse.ui.internal.quickaccess.QuickAccessContents$2.modifyText(QuickAccessContents.java:522)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:179)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4423)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1388)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3771)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3391)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1122)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1006)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:147)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:620)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:571)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:125)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:133)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:103)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:374)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:228)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:648)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1462)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1438)
Comment 13 Dirk Fauth CLA 2014-02-21 07:29:37 EST
The reason for this is an invalid contributorURI, that is technically valid.

See Bug 428728

It appears when trying to enter values in the Quick Access. As in the ModelProcessor the contributorURI is set to "bundleclass://org.eclipse.e4.tools.emf.liveeditor" without specifying a class, the String transformation fails with that exception.

I aggree that this should be made more fail safe and the error should be logged.

After response from Paul about the API question I will create an additional patch to solve the issues reported.
Comment 14 Paul Webster CLA 2014-02-21 08:17:39 EST
(In reply to Thomas Schindl from comment #5)
> +1 on making the translation package API with Luna

OK, if you think that's fine.  You can remove the x-internal (mark that package as visible to downstream plugins if using the tool).

Then we need to make sure that this kind of error simply is logged and doesn't interfere with any other attribute.

PW
Comment 15 Dirk Fauth CLA 2014-02-21 08:25:55 EST
See https://git.eclipse.org/r/#/c/22365/
Comment 17 Dirk Fauth CLA 2014-02-21 09:55:15 EST
I fetched origin/master, tested the two translation examples and executed the szenario Lars described. In all cases everything looks fine. Also the API warning is gone.

Therefore I mark this ticket as resolved as it was requested in comment 3.
Comment 18 Paul Webster CLA 2014-03-04 12:23:02 EST
By inspection in 4.4.0.I20140303-2000

PW
Comment 19 Dirk Fauth CLA 2014-03-05 07:33:20 EST
Downloaded and installed 4.4.0.I20140303-2000

Imported my projects from GitHub that are making use of the new features. Started the sample applications without any further modifications, and everything works as expected.