|
Figure 1. Current architecture of internationalization in GTK+.

Manipulating Text
The most basic task that GTK+ (and applications using
GTK+) have to handle when dealing with international
text is manipulating strings. The strings in the
GTK+ interfaces are handled in the multi-byte
encoding for the locale. This allows good
compatibility with existing applications that aren't
explicitely enabled for multi-byte support. Internally,
GTK+ converts these strings to wide-character strings
for easier manipulation, and the
conversion routines are also available for applications
that need these facilties.
Input
Internationalized input in GTK+ is done using the X Input
Method extension (XIM). The X Input Method extension is an
interface between X Window System applications and
input methods. An input method handles
translating keystrokes into characters. The X libraries
include a simple built in input method that does compose-key
handling for European languages. The more complicated input
method handling for Asian languages is typically done by an
external program.
You can see the basic architecture of XIM in Figure 1 in the section called Internationalization in GTK+. GTK+ forwards the keystrokes it receives to the
input method via Xlib, and when a complete input string is
received, it is displayed to the user. From the point of view
of an application which is just using the standard GTK+ Text
and Entry widgets, this is all done transparently behind the
scenes, and the application only sees the final strings.
The X Input Method extension provides a complete set of
facilities, and input methods are available for Chinese,
Japanese and Korean. However, the programming interface that
XIM provides has a number of disadvantages. For one thing,
strings are communicated using the native encoding for the
current locale and input methods are also selected by looking
at the current locale. This makes it difficult to use XIM to
do input in multiple languages at once. Also, the functioning of XIM
is very closely tied to the event handling and text string
models of X. An application that renders strings itself
(for instance, an illustration program) will have a hard
time using XIM.
Output
GTK+ handles output of strings in different scripts
using font sets. A font set
is a list of X fonts for different character sets.
When drawing, for example, mixed Roman and CJK
text, then the two different fonts needed are extracted
with multiple character sets.
The font to use for a particular widget is generally
determined in GTK+ using resource configuration (RC)
files. There is a system-wide file that the system
admininstrator can set up, and additionally, each user can
override the settings by creating a file in his home
directory. This mechanism has been extended to deal with
getting the correct fonts for each locale, even for user's
that switch between different locales. When GTK+ reads in a
RC file --- for example, the file .gtkrc
in the user's home directory --- it also looks for the same
file with an extension corresponding to the current locale. If
the locale is ja_JP then GTK+ will check
for the file .gtkrc.ja.
GTK+ ships with gtkrc
files for Japanese, Korean, and Russian, and a system
administrator can easily create them for additional languages
as needed.
|