views:

697

answers:

2

I have a contributed view in an Eclipse RCP application. This view has a localized name %view.name, with the translation on a plugin.properties file to "My View Part".

I am looking into the source code of Eclipse to understand how the internationalization works. So far, I haven't been able to find at what point the value from the properties file is read and assigned as the name of the view.

If I start from the resource reading part, I see that the class ManifestLocalization reads the properties file, but I can't find where it is used.

If I start from the name assignment, I see that the TableReader class gets the name of the view part, but it is already localized. I also saw that Eclipse converts this plugin.xml into some serialized object at some point. Maybe it is done for performance reasons?

So my question is, at what time is this "%view.name" string converted into "My View Part"

A: 

This can vary depending on the specific version of Eclipse, but it looks like the translation is happening in ResourceTranslator.getResourceString(Bundle, String, ResourceBundle)

For a view part contribution, this happens when the plugin manifest is loaded as part of ExtensionRegistry.addContribution().

You are correct that the translated version is cached. If you set breakpoints in the methods I mentioned, you'll notice that they only fire when the workspace is first initialized. In order to make them fire again, you have to clear the configuration area of the workspace.

Jordan Liggitt
+2  A: 

There is at least two mechanisms supporting localization in eclipse: the NLS, and the org.eclipse.core.runtime.registry.IConfigurationElement. The part you are interested in occurs in the IConfigurationElement.

When the IConfigurationElement.getAttribute(String key) is called, the ResourceTranslator.getResourceString() method uses the Bundle-Localization header in the OSGi manifest to find the correct properties file (usually this is plugin${locale}.properties) and entry in the properties file.

You can get what is actually in the plugin.xml file by calling the getAttributeAsIs(String key) method instead.

jamesh
As time is about to expire, this seems to be the closet to the truth
Mario Ortegón
Found this in the Eclipse RCP javadocs:*Deprecated.* The method is equivalent to the getAttribute(String). Contrary to its description, this method returns a translated value. Use the getAttribute(String) method instead.
Peteter