14 - Eclipse Plugin Internationalization Tutorial

In today’s world internationalization has become really important. Good news is that Eclipse has internationalization support. This is achieved by externalizing strings to a resource bundle. In Eclipse plug-in’s there are many files which can contain Strings (seen by end user) such as plugin.xml, Views, Editors and more specifically all the GUI labels. 

In this chapter (eclipse plugin for internationalization) we will externalize strings (seen by end user) to a properties file called plugin.properties.

Externalizing Strings in plug-in manifest

In plug-in manifest file we need to externalize strings, such as the names of views, name of wizards and the labels of actions. Externalizing strings from the plug-in manifest file very simple and straight forward. The file plugin.properties contains all the extracted strings. Steps involved in externalizing strings are as follows:

1. create a plugin.properties file

2. provide key value pairs in resource bundle. Key are the datavalues to be used in code and value is actual human readable string.

Step 1: Create a resource bundle

First step is to create a new properties file in plug-in project. Right click on project > select new file as shown below. Name this file “plugin.properties”. It must be noted that the translated files for each targeted language should be named plugin_<language>_<country>.properties, where <language> and <country> represent the language and country.

     Eclipse Plugin creating new properties file in plugin

Edit the plugin.properties file and add following line to the file:

views.propertyviewname = Property Manager View

Next, open plug-in manifest editor and replace Property Manager View name with a descriptive key that starts with a percent (%) sign. These are the same keys that are used in the associated plugin.properties file. The only rule is that the keys need to be unique within the plug-in.

       Eclipse set the properties of view

In order to test if strings have been externalized correctly you can play around by changing Property Manager View name and launch eclipse runtime. Note: If your changes are not reflected in the eclipse runtime then try clean build on your project followed by launch of eclipse runtime.

Externalizing Strings in plug-in classes

Eclipse has excellent inbuilt support for externalizing Strings. These can be used in any Java Project not necessarily plugin project. Here ill give you brief introduction on how to use this support (Please refer to eclipse help for complete details). We will externalize strings from com.myplugin.rmp.preferences.PropertyManagerPreferencePage class created earlier in this tutorial.

In order to externalize strings from this class, right click on Source > Externalize Strings when this class is open in java editor.

      Eclispe Plugin externalizing the strings

This will open up Externalize strings wizard. You will notice that list displays all the strings from java file. 

In this wizard against each string - "Internalize" button can be used to mark the string as non-translatable using end-of-line comment.

       Eclispe Plugin marking string as non translatable

On the bottom of the page you can specify properties file where these strings have to be externalized. Change it to refer to existing resource bundle file (if you already have one). Click next and you will be displayed following message.

       Eclispe externalizing the strings message

Click Next, Last page will show you the summary of all the changes which will take place if you click finish. Verify your changes and press finish so that eclipse can automatically externalize strings into resource bundle.

   Eclipse Plugin summary of changes for externalize strings

Once you have finished review the generated code to see how eclipse have externalized all your strings into resource bundle.