Common Desktop Environment: Internationalization Programmer's Guide

Simple Text Basic Interchange

When a program communicates data to another program residing on a remote host, a need may arise for conversion of data from the code set of the source machine to that of the receiver. For example, this happens when a PC system using PC codes needs to communicate with a workstation using an International Organization for Standardization/Extended UNIX Code (ISO/EUC) encoding. Another example occurs when a program obtains data in one code set but has to display this data in another code set. To support these conversions, a standard program interface is provided based on the XPG4 iconv() function definitions.

All components doing code set conversion should use the iconv() functions as their interface to conversions. Systems are expected to provide a wide variety of conversions, as well as a mechanism to customize the default set of conversions.

iconv Conversion Functions

The common method of conversions from one code set to another is through a table-driven method. In some cases, these tables may be too large, hence an algorithmic method may be more desirable. To accommodate such diverse requirements, a framework is defined in XPG4 for code set conversions. In this framework, to convert from one code set to another, open a converter, perform the conversions, and close the converter. The iconv() functions are iconv_open(), iconv(), and iconv_close().

Code set converters are brought under the framework of the iconv_open(), iconv(), and iconv_close() set of functions. With these functions, it is possible to provide and to use several different types of converters. Applications can call these functions to convert characters in one code set into characters in another code set. With the advent of the iconv()> framework, converters can be provided in a uniform manner. The access and use of these converters is being standardized under X/Open XPG4.

X Interclient (ICCCM) Conversion Functions

Xlib provides the following functions for doing conversions.

X ICCCM Multibyte Functions 

ICCCM Wide Character Functions 

XmbTextPropertyToTextList() 

XwcTextPropertyToTextList() 

XmbTextListToTextProperty() 

XwcTextListToTextProperty() 


Note -

The libXm() library does provide the XmStringConvertToCT() and XmStringConvertFromCT() functions; however, these are not recommended because there are some hardcoded assumptions about certain XmString tags. For example, if the tag is bold(), XmStringConvertToCT() is implementation-dependent. Across various platforms, the behavior of this function cannot be guaranteed in all international regions.


Refer to "Interclient Communications Conventions for Localized Text" for more information.

Window Titles

The standard way for setting titles is to use resources. But for applications that set the titles of their windows directly, a localized title must be sent to the Window Manager. Use the XCompoundTextStyle() encoding defined in XICCEncodingStyle(), as well as the following guidelines:

Following is an example of displaying a localized title and icon name. Compound text is made from the compound string in this example.

include       <nl_types.h>  
Widget         toplevel;  
Arg            al[10];  
int            ac;  
XTextProperty  title;  
char           *localized_string;  
nl_catd        fd;   

XtSetLanguageProc( NULL, NULL, NULL );  
fd = catopen( "my_prog", 0 );  
localized_string = catgets(fd, set_num, mes_num, "defaulttitle");  
XmbTextListToTextProperty( XtDisplay(toplevel), &localized_string,
         1, XCompoundTextStyle, &title);  ac = 0;  
XtSetArg(al[ac], XmNtitle, title.value); ac++;  
XtSetArg(al[ac], XmNtitleEncoding, title.encoding); ac++;  
XtSetValues(toplevel, al, ac);

If you are using a window rather than widgets, the XmbSetWMProperties() function automatically converts a localized string into the proper XICCEncodingStyle().