Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

E4/RAP Integration/NLS

NLS

Lets have a look at the WorkbenchMessages class to explain the differences between NLS in RCP and RAP.

First we don't extend from NLS, since this doesn't help us to get session aware native language support:

 // RAP [fappel: need session aware NLS
 //public class WorkbenchMessages extends NLS {
 public class WorkbenchMessages {
   private static final String BUNDLE_NAME = "org.eclipse.ui.internal.messages";//$NON-NLS-1$

Second we change the class variables containing the translated values to instance fields.

 // public static String BundleSigningTray_Cant_Find_Service;
 public String BundleSigningTray_Cant_Find_Service;

Third we introduce a static get() method that returns an instance of the WorkbenchMessages class with the correct translations for the current session/request. Instances get cached internally once they were loaded so that they are available for reuse. This approach requires that a call to get() takes place from a thread that has access to the session or request context (normally UI Thread).

 public static WorkbenchMessages get() {
   Class clazz = WorkbenchMessages.class;
   Object result = RWT.NLS.getISO8859_1Encoded( BUNDLE_NAME, clazz );
   return ( WorkbenchMessages )result;
 }

Using this looks like the following:

 // String closeJobDialogMsg = ProgressMessages.ProgressMonitorFocusJobDialog_CLoseDialogJob;
 String closeJobDialogMsg = ProgressMessages.get().ProgressMonitorFocusJobDialog_CLoseDialogJob;

Unfortunately this isn't the whole story, since this doesn't help translating texts in e.g. plugin.xml files. To enable this we provide a patch plugin for the equinox registry to suppress the direct translation on bundle startup. As the actual translation uses some RWT classes the translation mechanism gets hooked during the start of the org.eclipse.ui bundle (ugly, ugly, ugly...).

Back to the top