Section 16.1. Externalizing the Plug-in Manifest


16.1. Externalizing the Plug-in Manifest

The plug-in manifest file contains a variety of strings for identifying elements of the plug-in. Some strings, such as plug-in identifiers and the unique IDs associated with extensions, do not need to be translated as they are never shown to the user. In fact, translating identifiers and unique IDs will likely break your plug-in. Other strings, such as the names of views and the labels of actions, need to be translated as they are seen by the user.

Externalizing the human-readable strings from the plug-in manifest file is straightforward. The file plugin.properties (a standard Java resource bundle file which you will create) contains the extracted strings. As an example, start with the following fragment from the Favorites plug-in manifest.

<plugin    ...    <extension point="org.eclipse.ui.views">       <category            name="Quality Eclipse"            >       </category>       <view            name="Favorites"            icon="icons/sample.gif"            category="com.qualityeclipse.favorites"                        >        </view>     </extension>     ... </plugin> 


The lines shown in bold are the ones containing strings that need to be extracted. The other lines contain text that does not need to be extracted, such as class names, identifiers, filenames, and version numbers.

Each string is replaced with a descriptive key that starts with a percent (%) sign. These are the same keys that will be used in the associated plugin.properties file. The only rule is that the keys need to be unique within the plug-in. You should also endeavor to give the keys descriptive names so that they are easily identifiable within the plugin.xml and plugin. properties files.

After extraction, the fragment will look like this:

<plugin    ...    <extension point="org.eclipse.ui.views">       <category             name="%favorites.category.name"             >       </category>       <view             name="%favorites.view.name"             icon="icons/sample.gif"             category="com.qualityeclipse.favorites"                          >       </view>    </extension>    ... </plugin> 


The plugin.properties file (created using the File > New > File command) would then look like this:

# Contains translated strings for the Favorites plug-in favorites.category.name=Quality Eclipse favorites.view.name=Favorites 


When the strings have been extracted to the plugin.properties file, they can be translated. The translated files for each targeted language should be named plugin_<language>_<country>.properties, where <language> and <country> represent the two-letter codes (ISO 639 and ISO 3166) used to signify the language and country (the country component is optional).

Tip

A list of ISO 639 language codes can be found at: www.unicode.org/onlinedat/languages.html A list of ISO 3166 country codes can be found at: www.unicode.org/onlinedat/countries.html


For example, the standard German translation would be named plugin_de.properties and would look something like this:

# Enthält übersetzten Text für die steckbaren Lieblingeh favorites.category.name= Qualitätseklipse favorites.view.name=Lieblinge 


Likewise, the standard French translation would be named plugin_fr.properties and would look something like this:

# Contient le texte traduit pour les favoris favorites.category.name= Éclipse De Qualité favorites.view.name=Favoris 




Eclipse(c) Building Commercial-Quality Plug-ins
Eclipse: Building Commercial-Quality Plug-ins (2nd Edition)
ISBN: 032142672X
EAN: 2147483647
Year: 2004
Pages: 200

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net