Example: Creating and enabling a locale

This example contains the steps necessary for creating and enabling a locale.

To create and enable a locale, follow these steps:

  1. Create (or have) a library and a source physical file.
  2. Copy an existing locale source file definition member (to a library and source physical file).
  3. Edit the copied locale source file member if you need to customize any of the categories within the locale source.
  4. Create the locale object.
  5. Enable the locale object by using system values or parameters on the user profile.
Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

Step 1. Creating a library and a source physical file

A library and a source physical file are needed to store the locale source file member. Locale-source-definition files that are system supplied include a list of the locale source file members that are included in the IBM® i operating system.

To create a library called localelib, follow these steps:

  1. On a command line, type CRTLIB and press F4 (Prompt).
  2. Type localelib for the name of the library and press Enter.

To create a source physical file (localesrc) in library localelib, follow these steps:

  1. On a command line, type CRTSRCPF and press F4 (Prompt).
  2. Type localesrc for the file name and press Enter.

Step 2. Copying an existing locale source definition

Locale-source-definition file members that are IBM supplied are located in library QSYSLOCALE, source physical file QLOCALESRC. See System-supplied locale source definition files for a list of the IBM-supplied locale source files.

IBM provides sources for many sample locales. Besides the locales that IBM provides, an open source repository that contains locale sources is available. See the POSIX type files at the Unicode Common Locale Data Repository (CLDR) Web site Link outside information center for more information.

In this example, member EN_US, a locale for the English language, is copied.

To copy a locale source definition, follow these steps:

  1. On a command line, type CPYF and press F4 (Prompt).
  2. Type the values shown on the following display.
    Copy File (CPYF)                                                                
                                                                                    
    Type choices, press Enter.                                                      
                                                                                    
    From file  . . . . . . . . . . .   QLOCALESRC    Name                           
    Library  . . . . . . . . . . .     QSYSLOCALE  Name, *LIBL,*CURLIB              
    To file  . . . . . . . . . . . .   localesrc_    Name, *PRINT                   
    Library  . . . . . . . . . . .     localelib_  Name, *LIBL,*CURLIB              
    From member  . . . . . . . . . .   EN_US         Name, generic*,*FIRST, *ALL    
    To member or label . . . . . . .   EN_US_____    Name, *FIRST,*FROMMBR          
    Replace or add records . . . . .   *ADD____      *NONE, *ADD,*REPLACE           
    Create file  . . . . . . . . . .   *YES          *NO, *YES                      
    Record format field mapping  . .   *MAP__        *NONE, *NOCHK,*CVTSRC          

    The values entered copy the EN_US member to the source physical file localesrc in library localelib.

    Note: When you copy a file that is tagged with a CCSID, you need to use the FMTOPT(*MAP) parameter to ensure that the copied source is converted to the CCSID of the to-file. Scroll ahead to see the FMTOPT parameter.

Step 3. Editing the copied locale source definition

If you want to use the IBM-supplied locale as it is included, you do not need to change it. You can continue with step 4, Creating the locale object.

In this example, edit the EN_US member to set the time-of-day keywords used in the LC_TOD category. To know more about the LC_TOD category, see LC_TOD category.

This example shows how to use Source Entry Utility (SEU) to edit the locale. You can also use an equivalent editor.

To edit the locale using SEU, follow these steps:

  1. On a command line, type STRSEU (Start Source Entry Utility) and press F4 (Prompt).
  2. Type the source file name (localesrc), library name (localelib), and source member name (EN_US) as shown on the following display.
    Start Source Entry Utility (STRSEU)                                             
                                                                                    
    Type choices, press Enter.                                                      
                                                                                    
    Source file  . . . . . . . . . .   localesrc     Name, *PRV                     
    Library  . . . . . . . . . . .     localelib_  Name, *LIBL, *CURLIB, *PRV       
    Source member  . . . . . . . . .   EN_US_____    Name, *PRV, *SELECT            
  3. Press Enter. The following display appears.
    COLUMNS . . . :    1  71           EDIT      localelib/localesrc       
    SEU==>  F_LC_TOD      EN_US                                            
    FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+...6 ...+... 7    
    *************** BEGINNING OF DATA*************************************          
    5967.00 comment_char <percent-sign>                                             
    5968.00 escape_char  <slash>                                                    
    5969.00                                                                         
    5970.00 %                                                                       
    5971.00 % 5761SS1         (C) COPYRIGHT IBM CORP. 1991,2008                     
    5972.00 % ALL RIGHTS RESERVED.                                                  
    5973.00 % US GOVERNMENT USERS RESTRICTED RIGHTS -                               
    5974.00 % USE, DUPLICATION OR DISCLOSURE RESTRICTED                             
    5975.00 % BY GSA ADP SCHEDULE CONTRACT WITH IBM CORP.                           
    5976.00 %                                                                       
    5977.00 % LICENSED MATERIALS-PROPERTY OF IBM                                    
    5978.00 %                                                                       
    5979.00 % FILE NAME  :    EN_US                                                 
    5980.00 %                                                                       
    5981.00 % COUNTRY/REGION: UNITED STATES                                         
    5982.00 %                                                                       
                                                                                    
    F3=EXIT   F4=PROMPT   F5=REFRESH   F9=RETRIEVE   F10=CURSOR   F11=TOGGLE        
    F16=REPEAT FIND       F17=REPEAT CHANGE          F24=MORE KEYS                  
                                   (C) COPYRIGHT IBM CORP.1991, 2008.      
  4. Use the SEU search function to locate LC_TOD. After the search is completed, the following display appears.

    As you can see, all LC_TOD category keywords have values of 0 and no descriptive names are declared for tname and dstname.

    COLUMNS . . . :    1  71           EDIT      localelib/localesrc      
    SEU==>       EN_US                                                              
    FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+...6 ...+... 7    
    6519.00                                                                         
    6520.00 LC_TOD                                                         
    6521.00                                                                         
    6522.00 tzdiff   0                                                              
    6523.00 tname    ""                                                             
    6524.00 dstname  ""                                                             
    6525.00 dststart 0,0,0,0                                                        
    6526.00 dstend   0,0,0,0                                                        
    6527.00 dstshift 0                                                              
    6528.00                                                                         
    6529.00 END LC_TOD                                                              
    ****************** END OF DATA****************************************          
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
    F3=EXIT   F4=PROMPT   F5=REFRESH   F9=RETRIEVE   F10=CURSOR  F11=TOGGLE         
    F16=REPEAT FIND       F17=REPEAT CHANGE          F24=MORE KEYS                  
    STRING LC_TOD FOUND.                                                   
  5. To create the correct LC_TOD values for CST and CDT in the locale (for 2007 and later years), type the following values for the LC_TOD keywords:
    tzdiff
    Type 360.

    This is the difference in the number of minutes between Greenwich meantime and the central time zone of the United States.

    tname
    Type CST.
    dstname
    Type CDT.
    dststart
    Type 3,2,1,7200.

    This string of integers means that daylight saving time starts the third month of the year, the beginning of the second week, the first day of the week, and 7200 seconds (120 minutes) after midnight local standard time.

    dstend
    Type 10,3,6,0.

    This string of integers means that daylight saving time ends the tenth month of the year, the beginning of the third week, the sixth day of the week, and 0 seconds after midnight local standard time.

    dstshift
    Type 3600.

    For detailed information about the LC_TOD keywords, see LC_TOD category.

    The SEU edit screen should match the following display.

  6. Press Enter to make the changes to the EN_US locale member.
    COLUMNS . . . :    1  71           EDIT      localelib/localesrc       
    SEU==>       EN_US                                                              
    FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+...6 ...+... 7    
    6519.00                                                                         
    6520.00 LC_TOD                                                         
    6521.00                                                                         
    6522.00 tzdiff   360                                                            
    6523.00 tname   "CST"                                         
    6524.00 dstname  "CDT"                                                    
    6525.00 dststart 3,2,1,7200                                                       
    6526.00 dstend   11,1,1,7200                                                       
    6527.00 dstshift 3600                                                           
    6528.00                                                                         
    6529.00 END LC_TOD                                                              
    ****************** END OF DATA ****************************************         
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
    F3=EXIT   F4=PROMPT   F5=REFRESH   F9=RETRIEVE   F10=CURSOR   F11=TOGGLE        
    F16=REPEAT FIND       F17=REPEAT CHANGE          F24=MORE KEYS                  
    STRING LC_TOD FOUND.                                                   
  7. Save the member and exit SEU.

You have now copied the IBM-supplied locale source member and customized the LC_TOD category.

Step 4. Creating the locale object

To create the locale object, follow these steps:

  1. On a command line, type CRTLOCALE and press F4 (Prompt). The Create Locale (CRTLOCALE) display appears.
  2. In the Locale name field, type the locale path name (the path name includes the location and the name of the locale source member).
  3. In the Source file path name field, type the source file path name (the location and name of the source physical file and the member name).
    Notes:
    1. Make sure that the locale source file you are using has the same characters defined as does the CCSID you specify on the CRTLOCALE command. If they do not have the same characters available, unpredictable results can occur. For example, the EN_US source file has lowercase letters defined. However, the lowercase letters are not available in CCSID 290.
    2. When you create locale objects, it is preferred to make the CCSID part of the locale object name. For example, EN_US created with CCSID 37 can be named EN_US37.
    Create Locale (CRTLOCALE)                                                       
                                                                                    
    Type choices, press Enter.                                                      
                                                                                    
    Locale name  . . . . . . . . . . > '/qsys.lib/localelib.lib/en_us.locale'____   
    ______                                                                          
    Source file path name  . . . . . > '/qsys.lib/localelib.lib/localesrc.file/en   
    _us.mbr'                                                                        
    Coded character set ID . . . . . > 37________    1-65533, *JOB                  
    Generation severity level  . . .   10____        10, 20                         
    Text 'description' . . . . . . .   my version of locale EN_US - contains my c   
    hanges_                                                                         
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
    Bottom                                                                          
    F3=Exit   F4=Prompt   F5=Refresh   F10=Additional parameters  F12=Cancel        
    F13=How to use this display        F24=More keys                                
  4. Press Enter to complete the creation of the locale object named EN_US in the library LOCALELIB.

Step 5. Enabling the locale object

You can enable locales system-wide by using the QLOCALE system value or for individual users by changing their user profile. To enable the locale system-wide, make EN_US the value for the QLOCALE system value. In this example, the locale support is enabled for one user.

To enable the locale for one user, follow these steps:

  1. On a command line, type CHGUSRPRF and press F4 (Prompt).
  2. Specify the user ID of the user and press Enter.

In the following portion of the Change User Profile display, the LOCALE parameter now has a value indicating that EN_US is the specified locale to be used by the user ID.

For more values                                                               
Locale . . . . . . . . . . . . .  QSYS.LIB/LOCALELIB.LIB/EN_US.LOCALE______     
_______                                                                         

After the user profile has been changed, any jobs initiated by the user ID have the EN_US locale associated with those jobs. The LANG environment variable is also initialized to the name of the locale.