Java Internationalization and Localization
by Jaric Sng
04/12/2001
Internationalization (I18N) and Localization is easier with Java,
in contrast with other, previous native applications. Credit
goes to IBM's Center for Java Technology, Silicon Valley.
Although it is much easier to use I18N and L10N due to the
different approaches by Sun and Microsoft, we are faced with new
challenges. On one hand we want to target a wider audience, without
maintaining two sets of code (using the Java "write once, run
anywhere" vision). On the other, we want to use as many features as
possible in the latest Java release. Of course, there is a limit to
what we can achieve.
In this article, we will look at employing the Java reflection
so that our Java applet utilizes system fonts found in Java SDK 1.3
as well as the MS VM implementation, while not causing backward compatibility
problems for Navigator 4.76 with Java 1.1.5. With this technique, we
will be able to solve the problem of Chinese, Japanese, and Korean
characters displayed as "blocks" in IE with MS VM.
The display of these characters with an English language OS in
Navigator 4 requires the necessary changes to the
font.properties file on a client machine. As for
Navigator 6 and IE, we just need to run the test applet and use the
correct font in our applet. That's it.
The issues
In JDK 1.1, font mapping between the Java logical fonts and system
physical fonts is achieved by making the necessary changes in
font.properties, which lists the font results only by
logical font names.
The situaion is much better now with JDK 1.3. We can get a
list of the user's system TrueType fonts or create it ourselves.
Similarly, Microsoft makes it possible to do this with their
own implementation. Due to the different implementations of Sun and
Microsoft, how can we provide a uniform access to these different
solutions?
The solution:
Java reflection and a helper class NEFontFactory uses the Factory pattern.
Before we can do this, we need to
- install the necessary font,
- identify the font name, and
- configure Netscape 4.
Accessing the system font listing
In JDK 1.1, we cannot access the system font listing except logical fonts
names. These logical fonts are mapped to the system physical fonts by
editing the font.properties found in the
..\lib directory (See Creating
font.properties.en for Netscape 4).
In JDK 1.1, the font listing API returns a list of logical font
names:
java.awt.Toolkit.getDefaultToolkit().getFontList() // deprecated since JDK1.2
In JDK 1.3, the listing of system fonts is available using the following:
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()
In MS VM, the listing of system fonts is available using the following:
com.ms.awt.FontX.getFontList()
Creating Font Object
In JDK 1.1, we cannot create the TrueType font using its name.
Instead we create the font using a logical font name, which is
mapped to a TrueType font in the font.properties.
Now in JDK 1.3, we can create the TrueType font simply by
specifying its name:
new Font(fontName, fontStyle, fontSize)
In MS Java, the system font is obtained via com.ms.awt.FontX:
public static Font getFont(String face, int style, int size, int flags);
public static Font getFont(String face, Vector v, int size);
Development environment
For your reference, the following hardware and software configurations
is recommended for use in our development environment.
Hardware
- Pentium 700MHz
- Memory - 256 MB
Software
- OS - Microsoft Windows 2000 (Professional)
- Netscape 4.0 with JDK 1.1.5 VM
- Netscape 6.0 with JDK 1.3.0_01 VM
- MS IE 5.0 with VM Release 5.0.0.3802
- Visual SlickEdit 6
- Jakarta Tomcat 3.2.1
- JDK 1.1.8
- JDK 1.3
- MS Java SDK
Installing the True Type Font
Getting it
One way is to install it from the MultiLanguage
Pack from Office 2000.
For a listing of fonts provided by the MultiLanguage Pack (including
the code pages and the languages they support), check out Administering
Fonts in an International Office.
Otherwise, let IE do the job for you. To download Simplify Chinese font,
simply access Chinese language News paper web
site in Singapore using IE. IE will prompt you to download the
necessary font in order to view the page. For the following fonts, try
the sites below:
- Korean font -- http://kr.yahoo.com/
- Japanese
font -- http://www.yahoo.co.jp/
We may be able to view the page in Chinese, but what font is IE
using to display the page?