I had to help someone internationalize their RCP application today and I didn’t really have a straight forward simple example to point them to so I figure I’d share something here for everyone’s benefit. I’ll use the famous RCP mail example to get things started. The first step in internalization is making sure our strings are externalized so translators can actually do something with them. For Eclipse plug-ins, there will be two places you need to externalize strings:
- Java artifacts (ie., .java)
- Plug-in related artifacts (MANIFEST.MF and plugin.xml)
Within Java files, the wonderful JDT tooling provides an Externalize Strings wizard (Source->Externalize Strings…):
Within plug-in artifacts, PDE also provides an Externalize Strings wizard (PDE Tools->Externalize Strings or click the hyperlink on the Overview page):
Once we have all our strings externalized, we need to create a fragment (e.g., org.eclipse.mail.nl1) to store our translations (File->New->Fragment Project):
From the screenshot above, you should see that the translated properties files are co-located in the same respective location of the original file. The translated properties files also have a naming convention of name_locale.properties (e.g., messages_es.properties).
So now that we have some translated properties file, how do we test our translations? PDE provides an easy way to set the locale you’re developing against… similar to the way you define a target platform. In the target platform preference page, head over to the Environment tab and choose the language you’re interested in:
Once you do that, simply launch like you normally would to test out the fancy translations:
That’s it! Also, if you need translations for Eclipse.org plug-ins… check out the Babel project!
Here is the code used in this tip if you need to take a test drive at home. Hope this helps.