Internationalization Welcome!
Welcome!
Index
Index

Introduction

Unicode Support , Win32 Resources , Input Method Editors

The global connectivity provided by the Internet will increase the demand for internationalized software products and place additional requirements on internationalized applications. For example, applications that are delivered and run over the Internet may need to adapt to the user's language at run time. Other applications will need to be multilingual and support a combination of different languages. Fortunately, Java was designed to support internationalization—its primitive character type is based on Unicode, which is an international standard for encoding written language elements. The Microsoft SDK for Java enhances the internationalization features of Java with support for double-byte character set (DBCS) encoding, Microsoft® Win32® (Win32) resources, and input method editors.


Unicode Support

Although the Java language includes support for Unicode strings, many text editors use DBCS encoding, and many text files contain DBCS strings, not Unicode strings. This causes two different problems:

The Microsoft Java compiler (JVC) translates DBCS literal strings in your source code to Unicode when it compiles the source into class files. When a browser with Unicode-enabled Java support (for example, the support in Microsoft® Internet Explorer version 3.0) runs these class files, the literal strings will appear correctly. Microsoft VM for Java contains working versions of the Runtime methods getLocalizedInputStream and getLocalizedOutputStream. These methods are part of the Java language specification. Using these methods, you can write Java programs that can convert between DBCS and Unicode.

Note DBCS is language-dependent. Therefore, getLocalizedInputStream and getLocalizedOutputStream use the language of your operating system as the basis for interpreting DBCS characters. Also, only use getLocalizedInputStream on input streams that are known to be ASCII or DBCS. Do not use it on input streams that are already Unicode.

Using the getLocalizedInputStream Method

The getLocalizedInputStream method converts DBCS to Unicode. To use it, you must first call Runtime.getRuntime() to get a run-time object. Then, call the run-time getLocalizedInputStream method, passing the input stream object you want to have converted. getLocalizedInputStream returns a DataInputStream object that does DBCS to Unicode conversion on the input stream. The following example demonstrates this:

Runtime rt = Runtime.getRuntime();
FileInputStream fisDBCS;
DataInputStream disUnicode;
String sInput;

fisDBCS = new FileInputStream("DBCS.TXT");
disUnicode = (DataInputStream)rt.getLocalizedInputStream(fisDBCS);
sInput = disUnicode.readLine(); 

The previous code excerpt shows that DBCS.TXT is a file containing DBCS text strings. fisDBCS is a file input stream object that opens the DBCS.TXT file. disUnicode is a DBCS-to-Unicode input stream that is created by passing fisDBCS through getLocalizedInputStream. The call to disUnicode.readLine() gets a line of DBCS text from DBCS.TXT, converts it to Unicode, and then places the resulting Unicode string in the sInput String object.

Using the getLocalizedOutputStream Method

The getLocalizedOutputStream method converts Unicode to DBCS. To use it, you must first call Runtime.getRuntime() to get a run-time object. Then, call the run-time getLocalizedOutputStream method, passing the output stream object that you want to have converted. getLocalizedOutputStream returns a DataOutputStream object that does Unicode to DBCS conversion on the output stream. Consider the following example:

Runtime rt = Runtime.getRuntime();
FileOutputStream fosUnicode;
DataOutputStream dosDBCS;
String sOutput = "This is a Unicode string";

fosUnicode = new FileOutputStream("OUTPUT.TXT");
dosDBCS = (DataOutputStream)rt.getLocalizedOutputStream(fosUnicode);
dosDBCS.writeChars(sOutput); 

The previous code excerpt, Output.txt, is a new text file that is going to contain DBCS text strings. fosUnicode is a file output stream object that opens the Output.txt file. dosDBCS is a Unicode-to-DBCS output stream that is created by passing fosUnicode through getLocalizedOutputStream. The call to dosDBCS.writeChars() converts the Unicode string sOutput to DBCS, and places the resulting DBCS string in the Output.txt file.


Win32 Resources

Win32 resources are used to isolate text and user-interface elements, such as menus and dialogs, from the executable part of a program. Although the advantage of using Win32 resources applies to all applications, they are particularly useful for applications requiring internationalization. Resource files can be localized and tested without having to rebuild an entire application.

The Microsoft SDK for Java supports the Win32 resource format, allowing you to use existing resource files with Java applications as well as use familiar tools and processes to create and localize new resources. The com.ms.ui package includes the Win32ResourceDecoder class for loading resource (.res) files by specifying an URL for the location of the resource file. This class also provides methods for accessing the individual resource elements within a resource file.


Input Method Editors

An input method editor (IME) is a program that allows computer users to enter complex characters and symbols, such as Japanese Kanji characters, using a standard keyboard. Internationalized versions of Microsoft Windows provide system IMEs for locales with languages using non-Latin alphabets (for example, Japanese, Korean, traditional Chinese, and simplified Chinese. The Microsoft Win32 Virtual Machine (VM) for Java provides IME support for Java applications with an Input Method Manager that hosts Java-based IMEs as well as existing system IMEs.

Input Method Manager

The Input Method Manager (IMM) provides applications with an interface for using and managing input method editors. The following is a list of classes for the Input Method Manager:

Both of these classes reside in the com.ms.util package. The DefaultInputManager.getInputMethod method returns an object of type InputMethodListener. Applications can use this object to activate the IME as well as change its position on the screen.

Java-Based IMEs

The Microsoft VM for Java fully supports IMEs written in Java. Java IMEs provide more flexibility and control for applications than system IMEs. The following is a summary of the features of Java-based IMEs:

The com.ms.util package contains the InputMethodListener interface class, which is the base class for Java IMEs. IMEs based on this class will be recognized by the Input Method Manager.

Existing System IMEs

The Input Method Manager supports existing system IMEs enclosed in a COM wrapper interchangeably with Java-based IMEs. However, there are some limitations associated with using system IMEs. You can use a Java-based IME on any system regardless of what language the system is localized for as long as the Microsoft VM for Java is installed, but with system IMEs, you're limited to IMEs supported by the IMM on the host system. For example you can't use a Korean system IME on a version of Windows 95 that is localized for Greece.

System IMEs are supported with the SystemIME class in the com.ms.util package. The SystemIME class implements the InputMethodListener interface by embedding a COM object to communicate directly with the system IMEs. The COM object receives keystroke messages from the IME and routes the result of the composition to the Input Method Manager and on to the application.

Top© 1997 Microsoft Corporation. All rights reserved. Legal Notices.