Internationalizing and Localizing Applications in Oracle Solaris

Exit Print View

Updated: July 2014
 
 

About Internationalization

The word internationalization is often abbreviated as i18n, because there are 18 letters between the letter i and n. Although there are different definitions of what internationalization means, in this book, internationalization means making programs generic and flexible so that requirements for markets around the world are accommodated.

Part of internationalization is making the product localizable, so that the user interface (UI) of an application can be translated with minimal changes in the source code of the application.

For example, consider a message text in a C program that is coded as follows:

    /* This is not internationalized code */
    printf("This message needs internationalization.");

This message when externalized into a message catalog using the gettext command is written as follows:

    /* This is internationalized code */
    printf("%s", gettext("This message is now internationalized."));

Another important part of internationalization is to allow processing of data belonging to different locales without changing the source code.

For example, consider that you have to sort an array of strings. Without internationalization, the source code would be as follows:

    /* This is not internationalized code, since strcmp() compares byte
       values, producing an invalid sort order */ 

    if (strcmp((const char *)string[q], (const char *)string[p]) > 0) {
        temp = string[q];
        string[q] = string[p];
        string[p] = temp;
    }

This method of sorting works if the characters to be processed are only from the English locale. However, for the code to handle characters from different locales, you must use locale-sensitive functions. Using a locale-sensitive function, the sorting method is written as follows:

    /* This is internationalized code, since strcoll() uses locale
       information to determine sort order */ 

    if (strcoll((const char *)string[q], (const char *)string[p]) > 0) {
        temp = string[q];
        string[q] = string[p];
        string[p] = temp;
    }