Project: Eclipse_Platform_UI
Bug 345468 Translations not occurring for handled menu items
Reported: 2011-05-11 12:44:47 | Status: resolved fixed

I hope I'm missing something here, but I fear I am not. The Eclipse SDK IDE for Cocoa adds menu items for Window > Minimize, Window > Zoom, Window > Bring All To Front. These are responsible for the following warnings seen on startup, as the org.eclipse.e4.ui.workbench.renderers.swt.cocoa fragment doesn't (yet) provide definitions: !ENTRY org.eclipse.ui 4 4 2011-05-10 20:14:24.880 !MESSAGE Unable to create menu item "null", command "org.eclipse.ui.cocoa.minimizeWindow" not defined !ENTRY org.eclipse.ui 4 4 2011-05-10 20:14:24.881 !MESSAGE Unable to create menu item "null", command "org.eclipse.ui.cocoa.zoomWindow" not defined !ENTRY org.eclipse.ui 4 4 2011-05-10 20:14:24.881 !MESSAGE Unable to create menu item "null", command "org.eclipse.ui.cocoa.arrangeWindowsInFront" not defined I'm creating some Eclipse 4-based implementations, but having to define them programmatically (I can't define them in a fragment.e4xmi as we don't know the applicable application element ids). I'm trying to ensure that these definitions use translatable strings, if present. My initial attempt fails, however: MCommand zoom = MCommandsFactory.INSTANCE.createCommand(); zoom.setElementId(commandId); zoom.setCommandName("%command.zoom.name"); zoom.setDescription("%command.zoom.desc"); zoom.setContributorURI("platform:/fragment/org.eclipse.e4.ui.workbench.renderers.swt.cocoa"); app.getCommands().add(zoom); MHandler handler = MCommandsFactory.INSTANCE.createHandler(); handler.setContributionURI("platform:/plugin/org.eclipse.e4.ui.workbench.renderers.swt.cocoa/" + ZoomWindowHandler.class.getName()); handler.setContributorURI("platform:/fragment/org.eclipse.e4.ui.workbench.renderers.swt.cocoa"); handler.setElementId(ZoomWindowHandler.class.getName()); handler.setCommand(zoom); app.getHandlers().add(handler); But the menu items show up as "%command.zoom.name". It works if I instead use the injected TranslationService and explicitly perform the translation: command.setCommandName(translator == null ? name : translator.translate("%command.zoom.name", "platform:/fragment/org.eclipse.e4.ui.workbench.renderers.swt.cocoa")); command.setDescription(description == null ? description : translator.translate("%command.zoom.desc", "platform:/fragment/org.eclipse.e4.ui.workbench.renderers.swt.cocoa")); The BundleTranslationProvider does get called, except its contributorURI is null, and so no translation is attempted: BundleTranslationProvider.translate(String, String) line: 46 LocalizationHelper.getLocalized(String, MApplicationElement, IEclipseContext) line: 132 LocalizationHelper.getLocalized(String, MApplicationElement) line: 112 LocalizationHelper.getLocalizedLabel(MUIElement) line: 72 HandledMenuItemImpl(ItemImpl).getLocalizedLabel() line: 314 The problem is, I think, that the HandledMenuItem created takes its name from the command ("%command.zoon.name") but doesn't take the command's contributorURI, and instead has a null contributorURI. One solution might be to amend ItemImpl#getLocalizedLabel() and getLocalizedTooltip() to do something like this: public String getLocalizedLabel() { if(getContributorURI() == null && getLabel().equals(getCommand().getLabel()) { return LocalizationHelper.getLocalized(getLabel(), getCommand().getContributor()); } return LocalizationHelper.getLocalizedLabel(this); } (untested; it's a bit icky) Or alternatively, org.eclipse.ui.workbench's org.eclipse.ui.internal.menus.MenuHelper#createItem() should also set the newly-created menu item's contributorURI to the command's contributorURI? Or MHandledItem's implementation of #getContributorURI() should, if its contributorURI is null, return the command's contributorURI instead?

Files changed in fix:
bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuHelper.java