Tuesday, May 1, 2001

A beginners guide to developing localized applications

.KEYWORD localized
.FLYINGHEAD PROGRAMMING POWER
.TITLE A beginners guide to developing localized applications
.FEATURE
.SUMMARY In this global business environment, it’s vital to keep in mind that the Palm application you create in one country may need to be used throughout the world. Fortunately, the Palm OS is designed to be global. Steve Niles has done some research on localized applications, and in this article he shares some of what he’s learned and shows you where to find more information on this important topic for any international business attempting to develop proprietary software for Palm devices.
.AUTHOR Steve Niles
Having an international corporation is great from a business standpoint, as it opens up vast new markets. However, from a technical standpoint, it can be fraught with problems, as it’s necessary to bridge your software across language gaps. This holds true with software for Palm devices as well.

Suppose, for example, your London-based firm has developed a proprietary application for Palm devices that has increased employee productivity across the board. Everything is hunky-dory until the day comes when your company expands and opens a branch in Tokyo. Your new Japanese employees are all equipped with Palm devices, but your proprietary software is useless, since it’s completely designed in English.

In this global business environment, it’s vital to keep in mind that the Palm OS-based application you create in one country may need to be used throughout the world. Special attention must therefore be given in the programming phase to the particular characters, strings, numbers, and dates that are used, as different countries represent these items in different ways.

To understand more about programming these so-called "localized applications," I did some research on Palm’s Web site. I found a page devoted to the subject, and I’d like to share some of what I’ve learned. While this article may be of primary use to developers, it’s a valuable read for anyone working in a company that’s trying to integrate Palm computing into his or her international business.

This article is intended only as an introduction to localized applications. For the full details, be sure to visit http://oasis.palm.com/dev/kb/manuals/1747.cfm.

.H1 Terminology
In this discussion, there’s going to be a lot of talk of "strings." In computer science, a string is a set of consecutive characters that a computer treats as a single item, like a word or a phrase.

Characters in an alphabet are represented by computers using a numeric code. A "character encoding" is the set of numeric codes for a given alphabet, which includes all the letters of that alphabet, punctuation, numbers, control characters, etc. A "character set" is the entire set of characters a particular character encoding represents.

The Palm operating system can support multiple character encodings, but any given Palm OS device supports only one language, and thus only one character encoding.

.H1 Text manager and international manager
There are two managers provided with the Palm OS, the text manager and the international manager. They’re both designed to help you with localized strings and characters. The text manager lets you work with text, strings, and characters independent of the character encoding. The international manager detects the character coding being used by the particular Palm OS device and initializes the corresponding version of the text manager.

Both managers are supported starting in Palm OS version 3.1. If your application needs to work on older systems, you need to test for the presence of these managers before using text manager calls.

.H1 Strings
The Latin alphabet used by most European languages is relatively small. Therefore, its characters can be represented with a single-byte encoding ranging from 32 to 255. Asian languages, on the other hand, have their own alphabets, which tend to be quite large. Thus, these character sets are represented by a combination of single-byte and double-byte numeric codes ranging from 32 to 65,535.

On systems supporting the international and text managers, strings are made up of characters up to four bytes. Character variables are always two bytes long, but low ASCII (American Standard Code for Information Interchange) characters might be shrunken to a single byte by the operating system when you add them to a string.

Here are a few localization guidelines the Palm Web site recommends:

.BEGIN_LIST
.BULLET If you use the English language version of the software as a guide when designing the layout of the screen, try to allow extra space for strings and larger dialogs than the English version requires;
.END_LIST

.BEGIN_LIST
.BULLET Don’t put language-dependent strings in code. If you have to display text directly on the screen, remember that a one-line warning or message in one language may need more than one line in another language;
.END_LIST

.BEGIN_LIST
.BULLET Don’t depend on the physical characteristics of a string, such as the number of characters, the fact that it contains a particular substring, or any other attribute that might disappear in translation;
.END_LIST

.BEGIN_LIST
.BULLET Use as many parameters as possible to give localizers greater flexibility;
.END_LIST

.BEGIN_LIST
.BULLET Avoid building sentences by concatenating substrings together, as this often causes translation problems;
.END_LIST

.BEGIN_LIST
.BULLET Abbreviations may be the best way to accommodate the particularly scarce screen real estate on the Palm OS device;
.END_LIST

.BEGIN_LIST
.BULLET Remember that user interface elements such as lists, fields, and tips scroll if you need more space.
.END_LIST

For more interface guidelines, visit http://oasis.palm.com/dev/kb/manuals/1726.cfm.

.H2 Manipulating strings
Be careful not to point to an intra-character boundary (a middle or end byte of a multi-byte character) whenever you want to work with character pointers. Any time you want to set the insertion point position in a text field or set the text field’s selection, you need to use byte offsets that point to inter-character boundaries (the start of one character and the end of the previous character, except when the offset points to the very beginning or very end of a string).

Traditionally, C code uses a character pointer or byte counter to iterate through a string character by character. On systems with multi-byte characters, however, such code won’t work properly. There are text manager functions that you’ll need to use instead.

.H2 Dynamically determining a string’s contents
You should never hard code strings in a localized application. Rather, you should store them in a resource and use the resource to display the text. In order to create the contents of the string at runtime, you should store a template for the string as a resource. Then you can substitute values as needed.

.H1 Dates
If dates and times are used in your application, it will need to abide by the values set in the system preference by the user. Keep in mind that the default date and time preferences at startup are different for different languages. However, they can be overridden.

.H1 Numbers
Another thing to be careful of is that if your application displays large numbers or floating-point numbers, such as currency figures, you have to make sure you’re using the appropriate thousands separator and decimal separator for the country in which the device is being used.

.H1 Using overlays to localize resources
There’s added support for localizing resource databases through overlays in version 3.5 and above of the Palm OS. With localization, you can localize a software module without a recompile or modification of the software. Each overlay database is a separate resource database, providing a localized set of resources for a single software module (the PRC [Palm Resource File], or base database) and a single target locale (language and country). A single locale is supported by each Palm OS device.

When a PRC file is opened, the overlay manager determines what the locale is for this device and looks for an overlay matching the base database and the locale. According to the information provided on Palm’s localized applications page, "The overlay database’s name must match the base database’s name, its suffix must match the locale’s suffix, and it must have an ‘ovly’=1000 resource that matches the base database." It goes on to say that the overlay is opened in addition to the PRC file if the name, suffix, and overlay resource are all correct. The overlay is closed when the PRC file is closed.

Opened in read-only mode, the overlay is hidden from the programmer. You’ll receive a pointer to the base database, not the overlay, when you request a database pointer. Make resource manager calls like you normally would, and the resource manager will access the overlay where appropriate.

For more information on the overlay manager, visit http://oasis.palm.com/dev/kb/manuals/1760.cfm.

.H1 Japanese implementation
Currently, Japanese users must enter Japanese text into their Palm devices using Latin ASCII characters. An FEP (Front-End Processor) then transliterates this text into Hiragana or Katakana characters. The user can then use the FEP to phonetically convert Hiragana characters into a mixture of Hiragana and Kanji (Kana-Kanji conversion).

There are four additional silkscreen buttons added to Japanese devices to control the FEP transliteration and conversion process. The four FEP buttons are positioned between the left-most silkscreen buttons and the Graffiti area, as shown in Figure A.

.FIG A Four FEP buttons are added to the silkscreen area on Japanese Palm devices.

The functions of the FEP buttons are described on Palm’s localized applications page as follows:

.QUOTE The top-most FEP button tells the FEP to attempt Kana-Kanji conversion on the inline text. The next button confirms the inline text and terminates the inline conversion session. The third button toggles the transliteration mode between Hiragana and Katakana. The last button toggles the FEP on and off.

According to the information provided, Japanese text entry is always done inline, meaning transliteration and conversion happen directly inside of a field. Events are passed to the FEP by the field code, which then returns information about the appropriate text to display.

It’s recommended that to conserve screen space, whenever the string contains only Katakana characters you should use half-width Katakana characters on user interface elements such as buttons, menu items, labels, and pop-up lists. On the other hand, if the string contains a mix of Katakana and either Hiragana, Kanji, or Romaji, then you should use the full-width Katakana characters instead.

.H1 Conclusion
This should get you started thinking about the concept of localized applications. To really get a handle on the subject, be sure to pay a visit to the Palm manual on localized applications at http://oasis.palm.com/dev/kb/manuals/1747.cfm. It’s just one of many valuable technical resources available as part of the Knowledge Base section of the Palm Developer Support area at http://www.palmos.com/dev/tech/support/.

.BEGIN_SIDEBAR
.H1 Product availability and resources
For more information on localized applications, visit http://oasis.palm.com/dev/kb/manuals/1747.cfm.

For more information on interface guidelines, visit http://oasis.palm.com/dev/kb/manuals/1726.cfm.

For more information on the overlay manager, visit http://oasis.palm.com/dev/kb/manuals/1760.cfm.

For the Palm Developer Support area, visit http://www.palmos.com/dev/tech/support/.

For more information about Palm computers, visit http://www.palm.com.

.H1 Bulk reprints
Bulk reprints of this article (in quantities of 100 or more) are available for a fee from Reprint Services, a ZATZ business partner. Contact them at reprints@zatz.com or by calling 1-800-217-7874.
.END_SIDEBAR

.BIO
.DISCUSS http://powerboards.zatz.com/cgi-bin/webx?50@@.ee6f3be