22
Internationalization
In this chapter, I discuss the features in XView that allow applications to be international-
ized. For additional information on internationalization for XView Version 3.2, refer to the
XView 3.2 Developer’s Notes, Part II “Internationalization,” distributed by Sun Microsys-
tems, Inc. It describes the internationalization modifications by package as well as XView’s
wide character support. Internationalized applications do not have to be redesigned or
recompiled to run in a different language or locale. The goal is to make a single object ver-
sion of an application support any number of languages. The attribute XV_USE_LOCALE
enables the internationalization features. All internationalized applications must set this
attribute to TRUE.
The basic idea in internationalization is to separate language-specific data from the rest of
the application code. Adapting the application to any supported language, or localization,
then requires modification of only the language-specific data. The task of internationaliza-
tion includes translation of application-specific strings and modification of layout files. All
other aspects of the user interface are handled by XView.
The internationalization features discussed in this chapter are:
Locale Setting
Before running an internationalized application, a user must choose what language
to run in. This is done by the locale setting mechanism of XView.
Localized Text Handling
Developers need to be able to write application strings (error messages, menu labels,
etc.) in their native language and have those strings retrieved in the language speci-
fied by the locale. This process is described in Section 22.2, “Localized Text Hand-
ling.”
Object Layout and Customization
When an application is run in a non-native language, the dimensions of its strings
may change (among other things). This may cause the dimensions of objects with
text strings in them, such as buttons and panels, to change. Object Layout is the
mechanism by which the screen location of objects is modified to accommodate
these kinds of changes. Section 22.3, “Object Layout and Customization,” describes
how an application can be customized to accommodate various object layouts.
Internationalization
Internationalization 537
22.1 Locale Setting
This section describes the following internationalization topics:
Locale definition.
How to enable internationalization features in XView.
How to switch the locale from the OpenWindows Localization Properties Sheet.
How the locale is set in XView using locale attributes, command-line options, XView
locale resources, and the ANSI-C/POSIX setlocale() function.
Locale implementation limits and restrictions.
22.1.1 Locale Definition
In an internationalized program, the locale specifies the language and cultural conventions
used in a program. Locale setting affects the display and manipulation of language-depen-
dent features.
XView defines a program’s locale and the categories within each locale. These categories
refer to the language-dependent features defined by ANSI-C and OPEN LOOK. These features
include the display characteristics of monetary, numeric, and time fields.
XView offers several methods of setting locale. In order of priority, locale is set as follows:
1. XView locale attributes.
2. Locale command-line options.
3. XView locale resources (using the OpenWindows Workspace Property Sheet or an entry
in the X resource database).
22.1.2 Enabling Internationalization
The attribute XV_USE_LOCALE enables the internationalization features in XView. For inter-
nationalized applications to work properly, this attribute must be set to TRUE. This attribute is
only valid for xv_init(). The following is an example:
xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv,
XV_USE_LOCALE, TRUE,
NULL);
538 XView Programming Manual
22.1.2.1 Setting path of locale-specific files
The attribute XV_LOCALE_DIR specifies the location of an application’s locale-specific files.
The directory structure referenced by XV_LOCALE_DIR is:
<XV_LOCALE_DIR>/locale/LC_MESSAGES
<XV_LOCALE_DIR>/locale/app-defaults
<XV_LOCALE_DIR>/locale/app-defaults/<application name>
where locale is expanded differently depending on which internationalized feature is using
XV_LOCALE_DIR. For a discussion of the specific use of XV_LOCALE_DIR, refer to Section
22.2, “Localized Text Handling,” and to Section 22.3, “Object Layout and Customization.”
22.1.3 OpenWindows Localization Properties Sheet
The OpenWindows Localization Properties Sheet, shown in Figure 22-1, provides the
OPEN LOOK user interface for setting locale. To set locale, bring up the OpenWindows
Workspace Property sheet and choose “Localization” from the menu. The system then
allows you to specify the following categories within the Localization Menu:
Basic Setting
Specifies the country of the user interface. Once the Basic Setting is specified, the user
can set the specific settings. The specific settings define properties for each locale.
Display Language
Specifies the language in which labels, messages, menu items, help text, and so on, are
shown.
Input Language
Specifies the language used for input.
Time Format
Specifies the format for time and date displays.
Numeric Format
Defines the numeric format.
Supplementary Settings
Provides a selection of additional settings for any of the Specific Settings. That is, if
additional selections are required to specify Display Language, Input Language, Time
or Numeric Format, pressing the Supplementary Settings button will display them.
The Localization Property Sheet sets locale via XView locale resources in the X
resource manager database. This process is described later in this chapter. Once a set-
ting is made in the Localization Properties Sheet, subsequent applications will adopt
the new environmental settings.
Internationalization
Internationalization 539
Category: Localization
Basic Setting:
Specific Setting:
Display Language:
Input Language:
Time Format:
Numeric Format:
English
English
12/31/89 21:30:30
10,000.0
U.S.A.
U.S.A.
France
Workspace Properties
Supplementary...
ResetApply
Figure 22-1.
OPENLOOK
localization menu
22.1.4 XView Locale Attributes
Several attributes let you specify the locale from within an application. Each of these locale
attributes corresponds to the locale parameters described for the OpenWindows property
sheet. The attributes are shown in Table 22-1.
Table 22-1. XView Locale Attributes
Locale Parameter XView Attribute
Basic Setting XV_LC_BASIC_LOCALE
Display Language XV_LC_DISPLAY_LANG
Input Language XV_LC_INPUT_LANG
Numeric Format XV_LC_NUMERIC
Time Format XV_LC_TIME_FORMAT
These attributes specify the different
OPEN LOOK locale categories. They can only be set at
creation time through xv_init(), but can be queried at any time with xv_get() on any
object that is a subclass of WINDOW or SERVER. The value that is set using the above attri-
butes must be a valid locale name in the system.*
Locale attributes are used in situations when an application developer needs to force a pro-
gram to operate in a specific locale. For example, if a program only works in the French
locale, then the locale attributes can be used to hardwire the locale to French, preventing
*The valid locale names are dependent upon the operating system used.
540 XView Programming Manual
anyone from switching the locale using X resources or command-line options. Each of these
attributes takes a char * argument. Once again, these attributes are only valid for
xv_init() and xv_get(). For example, set the basic locale to French with the follow-
ing code:
xv_init( XV_USE_LOCALE, TRUE,
XV_LC_BASIC_LOCALE, "fr",
XV_INIT_ARGC_PTR_ARGV, &argc, argv,
NULL);
22.1.5 Command-line Options for Specifying Locale
The locale command-line options allow the locale to be set when an application is started.
These options may be used to override the system environment for a specific program. The
command-line options are shown in Table 22-2, and in Section 6, Command-line Arguments
and XView Resources, in the XView Reference Manual.
Table 22-2. Locale Command-line Options
Locale Parameter Command-line Option
Basic Setting –lc_basiclocale
Display Language –lc_displaylang
Input Language –lc_inputlang
Numeric Format –lc_numeric
Time Format –lc_timeformat
An example of these command-line options follows:
% textedit –lc_basiclocale fr –lc_displaylang C –lc_inputlang fr
This command line brings up a text editor with messages and panel labels in English. The
user’s input would be in French.
22.1.5.1 XView locale resources
Locale can also be set through resources written in the X11 Resource Manager database
(˜/.Xdefaults). The workspace property sheet uses the XView Locale Resources to set locale
parameters. Resources are shown in Table 22-3.
Internationalization
Internationalization 541

Get Volume 7A: XView Programming Manual now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.