Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Externalizing strings in plugin.xml for Eclipse plugin

How do I externalize strings in my Eclipse plugin's plugin.xml?

Right-clicking on the plugin project > PDE Tools > Externalize Strings does not show up my plugin.

I'm trying to do this manually now. I added entries in plugin.properties and replaced the equivalent string in plugin.xml with a % sign followed by the string key. But that does not seem to work. What am I missing here?

like image 276
Debajit Avatar asked Mar 13 '09 22:03

Debajit


2 Answers

I finally figured out how to manually externalize the plugin.

Eclipse, it turns out, externalizes plugin.xml this way:

  • In the plugin manifest (META-INF/MANIFEST.MF), add the following line

    Bundle-Localization: plugin
    

    where you intend to store the externalized strings in a file called "plugin.properties" (Turns out this was the missing piece).

  • Add the externalized string key-value pairs in plugin.properties.

  • Replace the actual strings in plugin.xml with the keys from plugin.properties (prefixed with %).

like image 71
Debajit Avatar answered Oct 12 '22 19:10

Debajit


If your working set have plugin projects in it, the Externalize Strings wizard to help externalize strings in your Manifest and plugin.xml files should be available.
Externalizing manifest files extracts translatable strings and stores them in a properties file for multi-language support.

The wizard is available under the PDE Tools menu in the context menu of a PDE project's MANIFEST.MF or plugin.xml files.

alt text
(source: eclipse.org)

Be aware that there were some bugs related to detecting all non-externalized attributes/values of the <extension-point> and <extension> elements, or showing up un-externalized names of extension(-point), which are only solved in 3.4 or very recent 3.5M4.

However, if the "Externalize Strings" menu does not show up at all on your plugin projects, may be its "project nature" is corrupted somehow, may be your former Java project is not properly converted to a PDE project ?

So two suggestions:

  • try with a fresh install of an eclipse3.5M4
  • import your plugin project and check its nature

And then tell us if that menu is still unavailable.


As you mention in your own answer, the externalization process is declared by the string

Bundle-Localization: plugin

in the MANIFEST.MF file, as mentioned in this message.

A bug has been created, but:

  • The localization is not something specific to PDE but instead the OSGI specification
  • that line is not always in the MANIFEST:

    Prior to 3.3, we created all our manifests by creating a plugin.xml and then converting it. The converter always added "Bundle-Localization: plugin" to the Manifest, since that is the default location if the plug-in has no Manifest.
    If a plug-in had no translations files, this header was unnecessary bloat.
    In 3.3, we created plug-in projects by creating Manifest directly, which means we decided to create only the headers necessary for project creation.

  • it is likely to be an issue for those that have created bundles with externalization < 3.2, and then not being able to see them when running in 3.3.

like image 43
VonC Avatar answered Oct 12 '22 21:10

VonC