No matter what be the project you are working on whether you are creating an
eclipse plugin, or a simple Java project you must deal with
internationalization. To some extent the string externalization wizard provided
by eclipse does solve some of the issues and hastens development speed.
However the code generated is definitely limited in purpose.
- For parameters you are forced to create an object array and deal with
indexes on your own when using the MessageFormat class. This approach is
both inelegant and definitely not so object oriented.
- You are forced to deal with and manage keys in your code and the
property file again without any elegance.
Design aspects that need to be made configurable are:-
- What to cache and how to cache. Should one not do the caching at all as
after all the Java API itself does some caching for the resource bundles.
- Whether there will be only one locale (the default locale) or whether
there will be multiple locales.
- Toggling the key types between - String / int /enum and addressing related
issues. (enum types will be used only for JDK1.5)
- Whether message formatting is to be done by means of MessageFormat or the
Formatter introduced in Java 1.5
Other issues
- Can we avoid writing the properties files and managing them by hand?
- Can the issue of plurals be dealt with automatically?
- Can we forget the mechanical coding of creating the object array (this is
less of an issue with Java1.5) and dealing with MessageFormat?
- Can we have a more elegant code such as "String
getKey1Msg(int
param1, String param2, Date, param3, Integer param4) which can serve as a
facade around the details of the actual object array creation" (In
Java1.5 there is no need for the explicit object array and object creation
because of varargs and auto-boxing and unboxing)?
- Can the keys be kept as constants in a Java interface (or a enum type in JDK1.5
)?
- Instead of dealing with a clutter of code and keys and properties files
can we manage them in a more systematic manner.
- Can the internationalization needs of exception classes also be addressed
similarly?
- Can we quickly locate keys for locales which do not have entries?
- Can we use standard keyboard
mappings for a locale and transparently get the correct property file
entries in a WYSIWYG fashion rather than feed in unicode by hand for any
locale?
- As we go about creating the entries against a locale and a key can we see
a preview of the actual message that will be finally delivered to code that
uses the generated code taking into consideration the different
parameters even before we actually were to generate the code and the
properties files?
-
can we transparently convert between
java.lang.String.format("pattern", varargs) and
java.text.MessageFormat("pattern", varargs) code and
resourcebundles without any effect on the client? [TODO have to provide for
java.lang.String.format("pattern", varargs) before this
converter cam be used]
Yes we can address all these issues and more using the RB plugin! *
The RBPlugin provides you a set of wizards and editors to create and edit a
XML metadata file. This metadata rb file is where all the above mentioned and
more issues are configured using the wizards and editors. The built in
code-generator delivers the properties files and java code freeing the developer
from all concerns of internationalization. at the minimum it reduces lines of
code. When working with the resource bundles it eliminates ambiguity by ensuring
that users work with identifiable names instead of the confusing index of object
in a object array or varargs. Moreover it provides means for tweaking code
internals for performance as per design requirement.
How
* point XI is a TODO
Copyright © R.Raghuraman. Distributable under LGPL
license.
|
JXPRESS. |
|