OpenJUMP
How to use i18n Internationalization

Introduction

There exists 2 ways for internationalizing the user interface.

both are described below

a) Internationalization with i18n

Since OpenJUMP nightly built Nov. 2007…

The updates done in November 2007 for the I18N class supports different resource files for plug-ins.

To use it in your plug-ins you will need to do the following, assuming
your plug-in is in the package com.foo.jump.bar

  1. Create a language package in the resource directory of you source for your resource bundles. Using MAVEN the directory would be src/main/resources/com/foo/jump/bar/language
  2. Add the jump.properties file (and other language files) into the directory created in 1
  3. Use the method
    I18N.getText(“com.foo.jump.bar”,”com.foo.jump.bar.MyPlugin.some-text-key”)
    in your plugin to get the I18Nized text
  4. Make sure when you build your jar file the whole directory tree under src/main/resources is copied to the jar file. With MAVEN this is done for you.

The new code uses the plug-in classloader so it should be able to find the resource bundle as long as you don’t use your own classloader.

b) Using Resource Bundle Class

Holger suggests to use the ResourceBundle- Class (Java Standard). This works with all versions of JUMP. Here the is the Hello World Example:

package example;

import com.vividsolutions.jump.workbench.plugin.*;
import java.util.*;

public class MyInternational
    extends AbstractPlugIn
{
  // this is the path to the propertie- files
  //    myinternational.properties       = language not suported
  //    myinternational_de.properties    = german
  //    myinternational_en.properties    = english
  //    etc.

  String basename = "example.resources.myinternational";
  ResourceBundle res;

  public MyInternational()
  {
  }

  public void initialize(PlugInContext context) throws Exception
  {

    res = ResourceBundle.getBundle(basename);

    // example 
    System.out.println(getString("Text1"));

    context.getFeatureInstaller().addMainMenuItem(this,
                                                  new String[]
                                                  {getString("Tools"),
                                                  getString("MyPlugins")},
                                                  getName(), false, null, null);
  }

  public boolean execute(PlugInContext context) throws Exception
  {
    context.getWorkbenchFrame().getOutputFrame().createNewDocument();
    context.getWorkbenchFrame().getOutputFrame().addText(getString("Hallo"));
    context.getWorkbenchFrame().getOutputFrame().surface();
    return true;
  }

  public String getName()
  {
    return getString("Name");
  }

  private String getString(String s)
  {
    try
    {
      return res.getString(s);
    }
    catch (MissingResourceException ex)
    { // no entry 
      ex.printStackTrace();
      return "";
    }
    catch (Exception ex)
    { // no resource file
      ex.printStackTrace();
      return "";
    }

  }
}