[jsword-devel] i18n and Actions
DM Smith
jsword-devel@crosswire.org
Thu, 01 Apr 2004 21:49:44 -0500
The EirAbstractActions derived classes all have hard coded strings. This
makes internationalization a little bit of a chore as the "Java way" of
getting international strings is via a ResourceBundle per class.
In an effort to do Internationalization and Localization (i18n and l10n) I
used a pattern for actions that was in a tutorial on actions on the Sun web
site and it served well.
The basic idea is this, Actions don't have behavior but just fire actions to
listeners. The listeners have the behavior for the actions that they care
about. To facilitate this an ActionManager singelton class is responsible
for creating Actions and for listening to Actions. The ActionManager is
responsible for forwarding ActionEvents to its ActionListeners. The
ActionEvents are manipulated so they seem like they come from the button,
menu item, check box or whatever that triggered the action event.
The advantage in the extra layer of the ActionManager, is that it is
responsible for creating actions and supplying actions by simple names
(createAction(...) and getAction(String simpleName). The action
characteristics are held in a ActionManager.properties file that is part of
the initialization of the singleton ActionManager, using ResourceBundle (or
more likely an extended ResourceUtil) to get the proper localization of the
action.
In the properties file each action would be of the form:
simpleName.LargeIcon=...
simpleName.SmallIcon=...
simpleName.MnemonicKey=...
Where the first element is the simple name (duh!!) and the second follows
the spelling of the key used in Action.putValue.
The file can have as many actions as it likes and each will be built. It can
have more than the applicatoin needs (i.e proceed it in development)
Listeners will distinguish Actions by simple name and act when one of
interest appears.
The primary impact of this is that the actionPerformed of each action needs
to be moved into the "actor" rather than actionPerformed being a delagate
for that actor.
Let me know what you think and whether this would be a worthy change to
make.
_________________________________________________________________
MSN Toolbar provides one-click access to Hotmail from any Web page – FREE
download! http://toolbar.msn.com/go/onm00200413ave/direct/01/