Sun Java Solaris Communities My SDN Account Join SDN
 
Solaris

Customizing and Creating Solaris Locales

 

To customize and thus create a new locale from existing locales, you need to have at least three locale definition source files:
  1. localedef source file
  2. charmap source file
  3. extension source file

The localedef source file contains necessary definitions for the locale.

The charmap source file contains mappings between codepoint values and human-readable symbolic names. The symbolic names are used in the localedef source file. The charmap source file also contains other definitions, such as the codeset name of the locale, the maximum number of bytes that can be represented in a locale codepoint, and so on.

The extension file contains mappings of standard interfaces such as strcoll() and fgetwc() to internal locale methods, and other information needed for the proper operation of the locale.

Usually the first step of the customization would be collecting necessary building blocks. Solaris has charmap and extension source files that you can use in the following directories:

    /usr/lib/localedef/extensions/
    /usr/lib/localedef/src/<locale>/

If you are customizing an ISO 8859 single byte locale, you can use localedef.src, charmap.src, and extension.src files in: /usr/lib/localedef/src/iso_8859_1/

NOTE: Since the localedef.src file at the above location only contains LC_CTYPE and LC_COLLATE definitions, you must supply any other locale category definitions either by using the "copy" keyword or providing your own definition. (The copy keyword, with some examples, is briefly described in an example below.)

If you are customizing a Japanese locale, you can use any of the Japanese locale files at:

    /usr/lib/localedef/src/ja/
    /usr/lib/localedef/src/ja_JP.PCK/
    /usr/lib/localedef/src/ja_JP.UTF-8/

You can also use the files in the /usr/lib/localedef/src/ja_JP.UTF-8/ directory to customize any other Unicode locales.

For any other locales, especially single byte locales, you can still customize by using the above files as reference and providing your own definitions.

NOTE: In future releases of Solaris, we hope to deliver all localedef source files for all Solaris locales in the /usr/lib/localedef/ directory. We will provide pointers to the localedef source files on the GADC web pages. Please stay tuned.

For the localedef source file, you can use existing files at the above locations, or supply your own file either by using the existing locales in your system or by defining your own locale definition.

The following example shows how to customize and create your own locale by using existing Japanese Unicode locale definition source files.

  1. Create a directory where you have at least about 10 megabytes of disk space, and change the current directory to there, and become super user:
        system% mkdir /tmp/test
        system% cd /tmp/test
        system% su
        Password:
        system#
    

    NOTE: The localedef(1) command will use a lot of system resources, especially memory and swap space. It is wise to use the best machine you have for faster locale generation. This is particularly true of Asian multi-byte locales. If you are customizing a single byte locale, you may need only about 300KB of disk space or less.

  2. Prepare a localedef source file such as the following and do necessary modifications:
    system# cat hi_IN.UTF-8@mynumber.src
    LC_CTYPE
    copy en_US.UTF-8
    END LC_CTYPE
    
    LC_COLLATE
    copy en_US.UTF-8
    END LC_COLLATE
    
    LC_MESSAGES
    copy en_US.UTF-8
    END LC_MESSAGES
    
    LC_TIME
    copy en_US.UTF-8
    END LC_TIME
    
    LC_NUMERIC
    decimal_point   "<period>"
    thousands_sep   "<comma>"
    grouping	3
    END LC_NUMERIC
    
    LC_MONETARY
    int_curr_symbol		"<I><N><R><SP>"
    currency_symbol		"<U0930><U0941>"
    mon_decimal_point	"<period>"
    mon_thousands_sep	"<comma>"
    mon_grouping		3
    positive_sign		""
    negative_sign		"<hyphen>"
    int_frac_digits		2
    frac_digits		2
    p_cs_precedes		1
    p_sep_by_space		0
    n_cs_precedes		1
    n_sep_by_space		0
    p_sign_posn		1
    n_sign_posn		1
    END LC_MONETARY
    

    For more detail on the categories and the fields, please refer to locale(5) and charmap(5) man pages.

    The "copy" keyword specifies to localedef(1) that you want to use another locale's category data as the definition of the category for the new locale. You must specify all six categories — LC_CTYPE, LC_COLLATE, LC_MESSAGES, LC_TIME, LC_NUMERIC, and LC_MONETARY — to build a locale. The codeset names of the locale that you are copying from and also your locale must exactly match. To find out if the codeset names are matching, you need to check the <code_set_name> field of your charmap file and the code_set_name value of the locale that you are copying from. Use the -k option of locale(1) to do this. For example, to do this for the en_US.UTF-8 locale:

        env LANG=en_US.UTF-8 locale -k code_set_name
    

  3. Copy necessary charmap and extension files to the current directory, and then use sed(1) for any other necessary modifications:
        system# cp /usr/lib/localedef/src/ja_JP.UTF-8/charmap.src .
        system# cp /usr/lib/localedef/src/ja_JP.UTF-8/extension.src .
        system# sed -e 's/ja_JP/en_US/g' < extension.src > extension.src.new
        system# sed -e 's:<mb_cur_max> 4:<mb_cur_max> 6:g' \
            < charmap.src > charmap.src.new
    

    If the two files charmap.src and extension.src are not in your system, you can add them by using the pkgadd command to install the SUNWjfpu package from your Solaris CD, DVD, or netimage. (For Solaris 8, the packages are located on the "Solaris Software 1 of 2" CD, in the .../Solaris_8/Product directory.)

    NOTE: Depending on your Solaris release, you may not have the Japanese Unicode locale definition source files in your Solaris medium. In Solaris 8 and later release, the files in the SUNWjfpu package.

    Make sure that the character between <mb_cur_max> and 4, as in the above example, is a single tab character. If you're customizing the Japanese Unicode locale, those two additional steps using sed(1) operations will not be necessary.

  4. Build the locale shared object by using the localedef(1) command. Make sure to have a C compiler available to use since localedef(1) will use the C compiler to generate locale shared object. (For more detail, refer to localedef(1) man page):
        system# localedef -f charmap.src.new -x extension.src.new \
            -i hi_IN.UTF-8@mynumber.src hi_IN.UTF-8@mynumber
    

    This will build a 32-bit locale shared object. Please be patient; it could take quite some time to generate, depending on your system performance. Please also ignore any warnings during the locale generation.

  5. Create the system locale directories and then copy the generated 32-bit locale shared object:
        system# mkdir -p /usr/lib/locale/hi_IN.UTF-8@mynumber/sparcv9
        system# cp hi_IN.UTF-8@mynumber.so.2 /usr/lib/locale/hi_IN.UTF-8@mynumber
    

    NOTE: If you're running 32-bit Solaris only, skip the next step, and go to the following one.

  6. Create the 64-bit version of locale shared object and then copy the 64-bit locale shared object to the system locale directory.
        system# localedef -m lp64 -f charmap.src.new -x extension.src.new \
            -i hi_IN.UTF-8@mynumber.src hi_IN.UTF-8@mynumber
        system# cp hi_IN.UTF-8@mynumber.so.2 \
    	/usr/lib/locale/hi_IN.UTF-8@mynumber/sparcv9
    
  7. You can now use the locale (and your number formatting) by setting the locale, e.g.:
    system% setenv LANG hi_IN.UTF-8@mynumberformat
    

Related Links