Internationalization |
18 |
![]() |
In order to type text of languages other than your own, you will need an X server which supports that language. You can find out if this is the case by checking whether the locale is present on your system. See the Locale Name section on page 589 for some hints on how to find out.
18.2 What is the Problem?
If your application is to be used by speakers of another language (even if that other language is British English rather than American English) you cannot assume that they understand your language and conventions. Apart from the variation in language, the use and style of addresses, date and time formats, personal names, even paper sizes may be very different from yours.
Other languages, such as Hebrew and Thai are alphabetic but still totally unlike Roman scripts. Some letters change according to context. There are often no spaces to distinguish words and some languages are written right to left while others are written left to right.
Although Japanese is used in most examples in this chapter, the principles are the same for any language.
18.3 Locale
Before you begin to address the issue of internationalization with regard to your application, you will need to understand how to set up your environment for a particular location. This involves an understanding of locales. A locale is an ANSI-C concept. It is a name that is used to identify a set of local information. For example, the locale might be set to be "en_UK" to denote that the location is the U.K. with English as the language, "en_US" for English as used in the U.S., or "ja" for Japanese. The setting of a locale makes certain C library functions operate in different ways, e.g. defining the sorting order, or date format. 18.3.1 Locale Name
You need to know the system name of the locale you are wishing to use and then set the LANG environment variable correspondingly so that applications can work out which language they should be displaying. Note that the name of the locale may differ depending on which system you are using. For a list of locale names supported by your UNIX system, look in the directory /usr/lib/locale. This will contain a directory for every language available. The directory names are used as the locale name, which is also the name you should use for the LANG environment variable. Type:locale -a
to list all locales currently installed on your system. 18.3.2 Specifying the Locale
To run WorkShop Visual with internationalization support, you must set an appropriate locale. Do this by setting the LANG environment variable before running your X server, for example:setenv LANG ja
This tells X to use Japanese for its display fonts and keyboard input, if Japanese is installed on your system.The value of the environment variable may be different on your system. See the Locale Name section above for more information.
18.4 Font Sets
Part of a locale's definition includes a specification of the font encodings required in order to display all possible text. For example, the Japanese locale requires that fonts with codesets ISO 8859-1, JIS X0208-1983 and JIS X0201-1976 be present in order to display all text in the Japanese language because Japanese contains Roman characters, Japanese alphabet characters (kana) and ideographic characters (Kanji). A FontSet is a collection of Fonts that contains all the required character sets for the current locale. 18.4.1 FontLists
The FontList is a collection of Fonts which is used for drawing labels in multiple fonts and styles. FontLists are specific to Motif whereas FontSets are defined by X.
18.4.2 What is the Connection Between FontSets and FontLists?
In order to incorporate FontSets, Motif's definition of a FontList has been extended so that each entry in a FontList can be either a single Font (FontStruct) or a FontSet.
See the Simple Font Objects section on page 155 for more information on font objects and the Creating a Complex Font Object section on page 177 for an explanation of FontLists.
18.4.3 Example of the Use of FontSets
The following exercise illustrates the use of FontSets.
Languages such as Hebrew and Arabic also require an input method because the letters change according to the position in the word and vowels are written around the consonant.
If an input method is required and you are running an appropriate version of WorkShop Visual, a special key sequence switches into using the input method when you enter text into a text field. The method converts the characters typed into corresponding characters in the target language.
For more information on international text on Sun platforms, see your Sun documentation.
static void initialise_objects( Widget parent )
{
char *from_s; /* For conversions */
XrmValue from_value, to_value; /* Ditto */
XmString temp_xmstring; /* For building XmString objects */
if ( _xd_initialised ) return;
_xd_initialised = 1;/* This is a string representation of a font list with a FontSet on the default tag. The colon (:) at the end designates it as a FontSet. */
from_s = "-jis-fixed-medium-r-normal--24-230-75-75-c-240- jisx0208.1983-0;-sony-fixed-medium-r-normal--24-230-75-75-c- 120-jisx0201.1976-0;-b&h-lucidabright-medium-i-normal--24-0- 100-100-p-0-iso8859-1:";
from_value.size = strlen(from_s)+1;
from_value.addr = (char *) XtMalloc ( from_value.size );
(void) strcpy ( from_value.addr, from_s );
XtConvert( parent, XmRString, &from_value, XmRFontList, &to_value);
XtFree ( from_value.addr );
font_resources.f1 = *(XmFontList*)to_value.addr;
}
void create_widget0 (parent)
Widget parent;
void create_widget0 (Widget parent)
{
.../* This is the string with all the escape sequences in it. */
xmstrings[0] = XmStringCreateLtoR("\033$BF| \033(B\033$B%[\033(B\033$B8l\033(B ", (XmStringCharSet)XmFONTLIST_DEFAULT_TAG);
XtSetArg(al[ac], XmNlabelString, xmstrings[0]); ac++;
XtSetArg(al[ac], XmNfontList, font_resources.f1); ac++;
widget5 = XmCreateLabel ( widget1, "widget5", al, ac );
ac = 0;
XmStringFree ( xmstrings [ 0 ] );
...
}
To see a text widget working with an input method from within WorkShop Visual, use the following steps.
XtSetLanguageProc ( (XtAppContext) NULL, (XtLanguageProc) NULL, (XtPointer) NULL );
A useful way to implement the correct FontList settings on an application-wide basis is to use loose bindings to declare a FontList resource binding, for example:
XApplication*FontList:
-misc-fixed-medium-r-normal-*-14-130-75-75-c-140-
jisx0208.1983-0;
-*-*-medium-r-normal-*-14-130-75-75-c-70-jisx0201.1976-0;
-misc-fixed-medium-r-normal-*-14-110-100-100
-c-70-iso8859-1:defaultwhere XApplication is the class name of your application. This example sets some Japanese fonts. The above example resource can be found in $VISUROOT/src/examples/loose_bindings/ja_fontlist.res and can be loaded into your design via the loose bindings dialog.
See the Loose Bindings section on page 90 for details on how to do this.
Note - The line breaks in the example above have been inserted for clarity - if you are editing a resource file you must make sure that there are no line breaks, otherwise the resource setting will be ignored.
18.8 Using Eight-Bit Characters in Shell Titles
If you intend to use a character with the eighth bit set in the title string of a Shell widget, you must make sure that the titleEncoding resource is set to "STRING". You can do this from within WorkShop Visual by specifying a loose binding which should look like this:XApplication*titleEncoding: STRING
(where XApplication is the class name of your application.)*titleEncoding: STRING
depending on whether you wish the resource binding to apply to all applications (as in the second example) or just your own application.
Alternatively, if you prefer to "hard code" the setting of this resource in your design, you can set the pre-manage prelude for the main Shell as follows:
XtSetArg ( al[ac], XmNtitleEncoding, XA_STRING ); ac++;
See the Shell Pre-manage Prelude section on page 260 for details on adding a pre-manage prelude to a Shell widget.