Version 0.2
Copyright © 2009 - 2010 Lars Vogel
10.08.2010
| Revision History | ||
|---|---|---|
| Revision 0.1 | 16.08.2009 | Lars Vogel |
| Created | ||
| Revision 0.2 | 10.08.2010 | Lars Vogel |
| bugfixes and enhancements | ||
Table of Contents
The process of preparing an application for beeing translated into several languages is called internationalization which is typically
Within Eclipse RCP and Eclipse plugins two elements are relevant for translation, entries in the plugin.mxl and text in the source code. abbriviated via i18n. This article describes how to internationalize both of them.

Create a new Eclipse RCP application "de.vogella.rcp.i18n" based on the "RCP application with a view" template. Have a look at the extension point "org.eclipse.ui.views" and validate that the name of the View is hard coded to "View".
Create the file "plugin.properties" in your plugin. This file can be referred to by the plugin.xml for strings. Add the following entry to this file.
View = Das hier ist Deutsch
To make OSGi aware that you want to use internationalization add the entry "Bundle-Localization: plugin" to your "MANIFEST.MF" file.
Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: I18n Bundle-SymbolicName: de.vogella.rcp.i18n; singleton:=true Bundle-Version: 1.0.0.qualifier Bundle-Activator: de.vogella.rcp.i18n.Activator Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-Localization: plugin
Now you can use the keys from plugin.properties in your plugin.xml via "%key".
<extension
point="org.eclipse.ui.views">
<view
name="%View"
class="de.vogella.rcp.i18n.View"
id="de.vogella.rcp.i18n.view">
</view>
</extension>
You can now create another plugin.properties file with the language key included, e.g. "plugin_en.properties". If the user language is set to english this file will be used.
View = Lars Test
Change "View.java"to the following.
package de.vogella.rcp.i18n;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.part.ViewPart;
public class View extends ViewPart {
public void createPartControl(Composite parent) {
Label label = new Label(parent, SWT.BORDER);
label.setText("This is a hardcoded text");
}
/**
* Passing the focus request to the viewer's control.
*/
public void setFocus() {
}
}
Right mouse-click on the source code. Select Source -> Externalize Strings. Select the strings which should be externalized

Press finished.
As a result a class Message.java is created which contains static member variables which can be used in the coding as String replacements. The message.properties contain the real strings. This has the advantages that you can use the Java tools to search for the usage of a string.
Copy message.properties to message_de.properties or message_en.properties to support different strings for different languages.
Thank you for practicing with this tutorial.
I maintain this tutorial in my private time. If you like the information please help me by using flattr or donating or by
|
Before posting questions, please see the vogella FAQ . If you have questions or find an error in this article please use the www.vogella.de Google Group . I have created a short list how to create good questions which might also help you. .
http://www.eclipse.org/articles/Article-SWT-graphics/SWT_graphics.html SWT Graphics
http://www-128.ibm.com/developerworks/opensource/library/os-ecllink// View linking, e.g. how can view 1 react to selection changes in view 2
http://www.eclipse.org/articles/article.php?file=Article-Understanding-Layouts/index.html Understanding Layout in SWT, updated version by Wayne Beaton
http://www.eclipse.org/articles/article.php?file=Article-AddingHelpToRCP/index.html Adding help to an Eclipse RCP application
http://wiki.eclipse.org/index.php/JFaceSnippets JFace Snippets (Code Examples for certain tasks)
http://www.eclipse.org/swt/snippets/ SWT Snippets (Code Examples for certain tasks)