Sun Microsystems Logo
Products and Services
 
Support and Training
 
 

Previous Previous     Contents     Index     Next Next
Chapter 4

Motif Dependencies

This chapter discusses tasks related to internationalizing with Motif.

Locale Management

The term language environment refers to the set of localized data that the application needs to run correctly in the user-specified locale. A language environment supplies the rules associated with a specific language. In addition, the language environment consists of any externally stored data, such as localized strings or text used by the application. For example, the menu items displayed by an application might be stored in separate files for each language supported by the application. This type of data can be stored in resource files, User Interface Definition (UID) files, or message catalogs (on XPG3-compliant systems).

A single language environment is established when an application runs. The language environment in which an application operates is specified by the application user, often either by setting an environment variable (LANG or LC_* on POSIX-based systems) or by setting the xnlLanguage resource. The application then sets the language environment based on the user's specification. The application can do this by using the setlocale() function in a language procedure established by the XtSetLanguageProc() function. This causes Xt to cache a per-display language string that is used by the XtResolvePathname() function to find resource, bitmap, and User Interface Language (UIL) files.

An application that supplies a language procedure can either provide its own procedure or use an Xt default procedure. In either case, the application establishes the language procedure by calling the XtSetLanguageProc() function before initializing the toolkit and before loading the resource databases (such as by calling the XtAppInitialize() function). When a language procedure is installed, Xt calls it in the process of constructing the initial resource database. Xt uses the value returned by the language procedure as its per-display language string.

The default language procedure performs the following tasks:

  • Sets the locale. This is done by using:

    setlocale(LC_ALL, language);

    where language is the value of the xnlLanguage resource, or the empty string ("") if the xnlLanguage resource is not set. When the xnlLanguage resource is not set, the locale is generally derived from an environment variable (LANG on POSIX-based systems).

  • Calls the XSupportsLocale() function to verify that the locale just set is supported. If not, a warning message is issued and the locale is set to C.

  • Calls the XSetLocaleModifiers() function specifying the empty string.

  • Returns the value of the current locale. On ANSI C-based systems, this is the result of calling:

    setlocale(LC_ALL,
    NULL);

The application can use the default language procedure by making the call to the XtSetLanguageProc() function in the following manner:

XtSetLanguageProc(NULL, NULL, NULL);
  		.
  		.
toplevel = XtAppInitialize(...);

By default, Xt does not install any language procedure. If the application does not call the XtSetLanguageProc() function, Xt uses as its per-display language string the value of the xnlLanguage resource if it is set. If the xnlLanguage resource is not set, Xt derives the language string from the LANG environment variable.


Note - The per-display language string that results from this process is implementation-dependent, and Xt provides no public means of examining the language string once it is established.


By supplying its own language procedure, an application can use any procedure it wants for setting the language string.

Font Management

The desktop uses font lists to display text. A font defines a set of glyphs that represent the characters in a given character set. A font set is a group of fonts that are needed to display text for a given locale or language. A font list is a list of fonts, font sets, or a combination of the two, that may be used. Motif has convenience functions to create a font list.

Font List Structure

The desktop requires a font list for text display. A font list is a list of font structures, font sets, or both, each of which has a tag to identify it. A font set ensures that all characters in the current language can be displayed. With font structures, the responsibility for ensuring that all characters can be displayed rests with the programmer (including converting from the code set of the locale to glyph indexes).

Each entry in a font list is in the form of a {tag, element} pair, where element can be either a single font or a font set. The application can create a font list entry from either a single font or a font set. For example, the following code segment creates a font list entry for a font set:

char font1[] =
 		"-adobe-courier-medium-r-normal--10-100-75-75-M-60";  
font_list_entry = XmFontListEntryLoad (displayID, font1,
  		XmFONT_IS_FONTSET, "font_tag");

The XmFontListEntryLoad() function loads a font or creates and loads a font set. The following are the four arguments to the function:

displayID

Display on which the font list is to be used.

fontname

A string that represents either a font name or a base font name list, depending on the nametype argument.

nametype

A value that specifies whether the fontname argument refers to a font name or a base font name list.

tag

A string that represents the tag for this font list entry.

If the nametype argument is XmFONT_IS_FONTSET, the XmFontListEntryLoad() function creates a font set in the current locale from the value in the fontname argument. The character sets of the fonts specified in the font set are dependent on the locale. If nametype is XmFONT_IS_FONT, the XmFontListEntryLoad() function opens the font found in fontname. In either case, the font or font set is placed into a font list entry.

The following code example creates a new font list and appends the entry font_list_entry to it:

XmFontList font_list;  
XmFontListEntry font_list_entry;
  		.
  		.
font_list = XmFontListAppendEntry (NULL, font_list_entry);  
XmFontListEntryFree (font_list_entry);

Once a font list has been created, the XmFontListAppendEntry() function adds a new entry to it. The following example uses the XmFontListEntryCreate() function to create a new font list entry for an existing font list.

XFontSet font2;  
char *font_tag;  
XmFontListEntry font_list_entry2;
  		.
  		.  
font_list_entry2 = XmFontListEntryCreate (font_tag,
  		 XmFONT_IS_FONTSET, (XtPointer)font2);

The font2 parameter specifies an XFontSet returned by the XCreateFontSet() function. The arguments to the XmFontListEntryCreate() function are font_tag, XmFONT_IS_FONTSET, and font2, which are the tag, type, and font, respectively. The tag and the font set are the {tag, element} pair of the font list entry.

To add this entry to the font list, use the XmFontListAppendEntry() function again, only this time, its first parameter specifies the existing font list.

font_list = XmFontListAppendEntry(font_list, font_list_entry2); 
XmFontListEntryFree(font_list_entry2);

Previous Previous     Contents     Index     Next Next
 

Updated: 2003-09-29, 21:36