[Home] [Search] [How to Buy] [Products] [Solutions] [Developers] [Services and Support] [Serious Fun]
sgi  
Developer Central
Developer ToolsProgram & BenefitsLibraryMarketing ResourcesTechnologyOpen Source
Library
image image image
Third Party Products
Directory
 
Members Only
Developer's
  Toolbox*
Developer News*
DevEdge Email*
KnowledgeBase*
Developer Consulting

 
Helpful Resources
Useful Links
Freeware
Video Server Toolkit
Year 2000
Technical Publications
  Library
Application Solution
  Center

 
Localization
Localization FAQ
* Programming Rules
Example Code
Glossaries

 
Archives
Developer News*
DevEdge*
What's New
Feature Stories
 
image  
 

Programming Rules

I18N Essentials - Programming Tips

Tip 1: Call a function to set language (locale) at the beginning of each program.

Call a setlocale() function for non-Xt/Motif programs. Because it affects sensitive functions, setlocale() should usually be called at the beginning of each program, but it can be called whenever necessary.

Call XtSetLanguageProc() for Xt/Motif programs. XtSetLanguageProc() must be called before Xt initialization, because it does NOT set a locale; it just registers a default language procedure which calls setlocale() (and other functions). Xt only calls the procedure specified for XtSetLanguageProc() when it is initialized, so calls after Xt is set up have no effect. It's probably better just to call XtSetLanguageProc() at the beginning of main().

Tip 2: Do not hard-code messages, labels, font names or most layout values.

  • Get messages from message catalog files for non-X based programs. Use catgets() functions.

  • Get messages, labels, font names and most layout values from resource files (or message catalog files) for X based programs. You can also define your own resources and use them. ViewKit has resource handling methods.


Tip 3: Use font sets instead of fonts.

  • Some Asian languages need several fonts. Fonts should be handled as font sets.
  • If you use Xlib functions, use XCreateFontSet() function instead of XLoadQueryFont() function, for font set.
  • If you use Motif functions and need to create font list in your program, use functions such as XmFontListEntryLoad(), XmFontListEntryCreate(), XmFontListAppendEntry().


Tip 4: Do not use special characters for widget names on Xt/Motif programs.

  • All widgets should have names because the use of NULL as a widget name makes it impossible to identify widgets for localization. Widget names should contain only ASCII alphanumeric characters and underbar; it is difficult or impossible to localize widgets whose names contain whitespace, punctuation or special characters such as '*', '.', ':' and '?'

  • One common practice causes particular problems: naming a widget using its label string often leads to widget names that are difficult to use, because labels sometimes contain special characters.


Tip 5: Do not fix widget arrangements and sizes of label, button, text widgets.

  • Length of messages or labels may change depending on the language. Do not adjust and fix a layout or sizes of widgets just for English.

  • Layout should change automatically based on language (locale). If it is difficult and time-consuming to determine the sizes for each widget manually, you need to define the sizes in resource files.

  • Because font width varies among languages, the number of columns of text (fields) for a widget can vary by as much as a factor of two. Therefore, this size should be adjusted automatically based on layout, or changed by values in a resource file. Do not hard-code it.

  • Using the Form widget is one relatively easy (and recommended way) to automatically adjust the layout of primitive widgets. Define values for ATTACH_* resources explicitly and correctly or the layout will be broken.

Tip 6: Use multi-byte functions for Xlib code fragment.

  • Use XmbDrawString() instead of XDrawString() for drawing text. (or XwcDrawString())

  • Use XmbLookupString() instead of XLookupString() for handling X events directly. (or XwcLookupString() )


Tip 7: Use multi-byte functions for text processing.

  • Do not assume characters are ASCII (1 byte, 7 bit). Some code sets use 8 bit for characters, while others may use multi byte (and 8 bit) characters.

  • Use multi byte or wide character functions for text processing such as mbtowc(), mbstowcs(), iswupper(), and isideogram().

  • In some languages, there are no spaces between words. This may affect algorithms for justification, pagination, word wrapping, etc.


Tip 8: Use Selection for Cut & Paste on Xlib base program.

  • Use Selection instead of Cut Buffer for Cut & Paste (inter-client communication).

  • Use compound texts for inter-client communications. Conversion to compound text is required.


Tip 9: Use LC_MESSAGES for getting message catalogs.

  • Be sure to use the LC_MESSAGES sub-category when deciding where to get message catalogs, HTML files, etc. Do NOT use the LANG environment variable directly and do not use LC_ALL for querying.

  • When calling catopen(), specify an OFLAG of NL_CAT_LOCALE . The man page for catopen says that this value must be 0, but the man page is out of date. The correct value is NL_CAT_LOCALE .


Tip 10: Use XPG4 message system function instead of gettxt()

Use the XPG4 message catalog functions (e.g. catopen(), catgets()). Some older interfaces (such as getttxt) are supported for compatibility but are deprecated. You may still use the getxt command in shell scripts.

privacy policy | webmaster
Copyright © 2000 Silicon Graphics, Inc. All rights reserved. | Trademark Information