artofillusion.ui
Class Translate

java.lang.Object
  extended by artofillusion.ui.Translate

public class Translate
extends java.lang.Object

This class provides utilities for localizing text so that it can be translated into different languages. It does this by loading strings from a resource bundle, and using them to create properly localized widgets.

The resource bundle is created from a PluginResource of type "TranslateBundle" provided by the PluginRegistry. By default it uses the PluginResource with ID "artofillusion" which is built into the application, but you can specify a different one by prefixing its ID to the property name passed to any method of this class. This allows plugins to provide their own ResourceBundles for localizing their strings. To do this, the plugin should include a set of properties files that define the localized versions of its strings, such as:

com/mycompany/myplugin.properties
com/mycompany/myplugin_fr.properties com/mycompany/myplugin_es.properties

In its extensions.xml file, it then provides a reference to these files:

<resource type="TranslateBundle" id="myplugin" name="com.mycompany.myplugin"/>

To look up keys from that bundle, prefix the key with the ID specified in the <resource> tag:

BLabel instructions = Translate.label("myplugin:instructionsLabel");


Constructor Summary
Translate()
           
 
Method Summary
static BButton button(java.lang.String name, java.lang.Object listener, java.lang.String method)
          Get a BButton whose text is given by the property "button.(name)".
static BButton button(java.lang.String name, java.lang.String suffix, java.lang.Object listener, java.lang.String method)
          Get a BButton whose text is given by the property "button.(name)", with a suffix appended to it.
static BCheckBoxMenuItem checkboxMenuItem(java.lang.String name, java.lang.Object listener, java.lang.String method, boolean state)
          Get a BCheckBoxMenuItem whose text is given by the property "menu.(name)".
static java.util.Locale[] getAvailableLocales()
          Get a list of the locales for which we have translations.
static java.util.Locale getLocale()
          Get the locale currently used for generating text.
static BLabel label(java.lang.String name)
          Get a BLabel whose text is given by the property "name".
static BLabel label(java.lang.String name, java.lang.String suffix)
          Get a BLabel whose text is given by the property "name", with a suffix appended to it.
static BMenu menu(java.lang.String name)
          Get a BMenu whose text is given by the property "menu.(name)".
static BMenuItem menuItem(java.lang.String name, java.lang.Object listener, java.lang.String method)
          Get a BMenuItem whose text is given by the property "menu.(name)".
static BMenuItem menuItem(java.lang.String name, java.lang.Object listener, java.lang.String method, Shortcut shortcut)
          Get a BMenuItem whose text is given by the property "menu.(name)".
static void setLocale(java.util.Locale l)
          Set the locale to be used for generating text.
static java.lang.String text(java.lang.String name)
          Get the text given by the property "name".
static java.lang.String text(java.lang.String name, java.lang.Object arg1)
          Get the text given by the property "name".
static java.lang.String text(java.lang.String name, java.lang.Object[] args)
          Get the text given by the property "name".
static java.lang.String text(java.lang.String name, java.lang.Object arg1, java.lang.Object arg2)
          Get the text given by the property "name".
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Translate

public Translate()
Method Detail

setLocale

public static void setLocale(java.util.Locale l)
Set the locale to be used for generating text.


getLocale

public static java.util.Locale getLocale()
Get the locale currently used for generating text.


getAvailableLocales

public static java.util.Locale[] getAvailableLocales()
Get a list of the locales for which we have translations.


menu

public static BMenu menu(java.lang.String name)
Get a BMenu whose text is given by the property "menu.(name)".


menuItem

public static BMenuItem menuItem(java.lang.String name,
                                 java.lang.Object listener,
                                 java.lang.String method)
Get a BMenuItem whose text is given by the property "menu.(name)". If listener is not null, the specified method of it will be added to the BMenuItem as an event link for CommandEvents, and the menu item's action command will be set to (name). This also checks for a property called "menu.shortcut.(name)", and if it is found, sets the menu shortcut accordingly.


menuItem

public static BMenuItem menuItem(java.lang.String name,
                                 java.lang.Object listener,
                                 java.lang.String method,
                                 Shortcut shortcut)
Get a BMenuItem whose text is given by the property "menu.(name)". If listener is not null, the specified method of it will be added to the BMenuItem as an event link for CommandEvents, and the menu item's action command will be set to (name). This form of the method allows you to explicitly specify a menu shortcut, rather than using the one given in the properties file.


checkboxMenuItem

public static BCheckBoxMenuItem checkboxMenuItem(java.lang.String name,
                                                 java.lang.Object listener,
                                                 java.lang.String method,
                                                 boolean state)
Get a BCheckBoxMenuItem whose text is given by the property "menu.(name)". If listener is not null, the specified method of it will be added to the BCheckboxMenuItem as an event link for CommandEvents. state specifies the initial state of the item.


button

public static BButton button(java.lang.String name,
                             java.lang.Object listener,
                             java.lang.String method)
Get a BButton whose text is given by the property "button.(name)". If listener is not null, the specified method of it will be added to the BButton as an event link for CommandEvents, and the menu item's action command will be set to (name).


button

public static BButton button(java.lang.String name,
                             java.lang.String suffix,
                             java.lang.Object listener,
                             java.lang.String method)
Get a BButton whose text is given by the property "button.(name)", with a suffix appended to it. If listener is not null, the specified method of it will be added to the BButton as an event link for CommandEvents, and the button's action command will be set to (name).


label

public static BLabel label(java.lang.String name)
Get a BLabel whose text is given by the property "name". If the property is not found, this simply uses name.


label

public static BLabel label(java.lang.String name,
                           java.lang.String suffix)
Get a BLabel whose text is given by the property "name", with a suffix appended to it. If the property is not found, this simply uses name.


text

public static java.lang.String text(java.lang.String name)
Get the text given by the property "name". If the property is not found, this simply returns name.


text

public static java.lang.String text(java.lang.String name,
                                    java.lang.Object arg1)
Get the text given by the property "name". If the property is not found, this simply uses name. Any occurrance of the pattern "{0}" in the text string will be replaced with the string representation of arg1.


text

public static java.lang.String text(java.lang.String name,
                                    java.lang.Object arg1,
                                    java.lang.Object arg2)
Get the text given by the property "name". If the property is not found, this simply uses name. Any occurrances of the patterns "{0}" and "{1}" in the text string will be replaced with the strings representations of arg1 and arg2, respectively.


text

public static java.lang.String text(java.lang.String name,
                                    java.lang.Object[] args)
Get the text given by the property "name". If the property is not found, this simply uses name. That string and the args array are then passed to MessageFormat.format() so that any variable fields can be replaced with the correct values.



Copyright © 1999-2011 by Peter Eastman.