Jalview i18n

Best practices

  1. Follow the standards described in this guide
  2. Always use properties files for user interface text; never include displayable text in code
  3. Use properties files only for user interface text (Messages_xx.properties) and config files for configuration settings (jalview.properties).
  4. Use a proper naming schema for keys in your resource bundles. The name of the keys should provide some information about the context of the displayed text. This helps the translators during the translation process.
  5. Group keys by view, ie. edit.title, edit.instructions, list.title, list.instructions, create.title, etc
  6. Never use displayable text when executing comparisons within the logic of the tool (separate codified values from displayable text)
  7. Always use the MessageManager class for retrieving properties values, and invoke MessageManager methods dynamically, to accommodate dynamic user preferences (see MessageManager below).
  8. All numbers and dates should be formatted specific to the user's locale (e.g. java.text.NumberFormat and java.text.DateFormat)
  9. Test code in more than one language

MessageManager

The jalview.util.MessageManager class is a wrapper class for the ResourceBundle class. It provides dynamic language/locale support for individual users, and is recommended for all Jalview code.

To use it within your code, you only have to invoke MessageManager with the text key in Messages_xx.properties:

JButton ok = new JButton(MessageManager.getString("button.ok"));

This will set JButton text to the one included at button.ok key. In English JButton text will be OK, while in Spanish will be Aceptar. This is the big thing of i18n. :)

Don't rely comparisons on labels

Don't use this type of coding: threshold.addItem("No Threshold");
threshold.addItem("Above Threshold");
threshold.addItem("Below Threshold");
[...]
if (threshold.getSelectedItem().equals("Above Threshold"))
{
aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
}
else if (threshold.getSelectedItem().equals("Below Threshold"))
{
aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
}

Once text has been translated, these equals will fail as the label won't be the English ones. It should be used getSelectedIndex() instead of getSelectedItem(). If you do the proper way, the code will look like this:
threshold.addItem(MessageManager.getString("label.threshold_feature_no_thereshold"));
threshold.addItem(MessageManager.getString("label.threshold_feature_above_thereshold"));
threshold.addItem(MessageManager.getString("label.threshold_feature_below_thereshold"));
[...]
if (threshold.getSelectedIndex()==1)
{
aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
}
else if (threshold.getSelectedIndex()==2)
{
aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
}

How to translate Jalview

Anyone interested in localizing/translating Jalview is strongly encouraged to join the Jalview Development List list. We would recommend that you read this entire page before proceeding.

If you are planning on working on a Jalview translation, please send us an email (Jalview Development List). There may be someone else already working on translating Jalview to your target language.

Once you have downloaded the source code (available at http://www.jalview.org/download), you must edit {jalview.home}/resources/lang/Messages_xx.properties, where xx refers to your language country code. If it doesn't exits, rename Messages.properties to Messages_xx.properties.

Next step...start transtalation!

Once you have it translated, we would appreciate if you contribute it forwarding the file to Jalview Development List. We will commit it to the code base as soon as possible. Thanks so much for this in advance!