![]() |
![]() |
| |||||||||||||||
Chapter 4Motif DependenciesThis chapter discusses tasks related to internationalizing with Motif. Locale ManagementThe 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:
The application can use the default language procedure by making the call to the XtSetLanguageProc() function in the following manner:
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 ManagementThe 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 StructureThe 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:
The XmFontListEntryLoad() function loads a font or creates and loads a font set. The following are the four arguments to the function:
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:
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.
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.
| |||||||||||||||
| |||||||||||||||