Developing Programs that Support Multiple Languages

When you modify the regional settings of your system to your preferred language the associated locale specific information such as Currency, Date and Time Format, Calendar etc get changed.

You can access this information from within your program using the appropriate functions.

The constants LOCALE_USER_DEFAULT and LOCALE_SYSTEM_DEFAULT are used to obtain the default locale of system or the current user. This constant points to a DWORD of type LCID. LCIDs point to Locale IDs.

Displaying the Calendar information using Current Locale Information.

You use the EnumCalendarInfoEx() function to enumerate the calendars in the system. This function takes a callback to the EnumCalendarInfoProc() function as a parameter. The callback provides a reference to CALID. This reference holds the current locale specific calendar. Pass this reference to the GetCalendarInfo() function. Using this function you can obtain the Month names, Day names etc that are associated with the locale specific calendar. The code below shows how to use these functions.

  1. Create a new project and select Win32 Project under Visual C++ Projects from Visual Studio.NET.
  2. Enter the project name you wish in the New Project dialog box.
  3. Allow the default settings in the Win32 Application Wizard and Select Empty Project option under Additional Options as shown in the figure below. Win32 Application Wizard
  4. Click Finish.
  5. From the Project menu select Project Properties item, the Project Property Pages Dialog Box appears as shown below.
    calendar Project Properties
  6. Select Use Unicode Character Set in the Character Set as shown in the above figure.
  7. Select Add Resource from the Project menu and select Dialog. Click New to create a new Dialog resource.
  8. Change the size of the dialog box and set its height and width in the dialog editor such that in can vertically display the 12 months. In this example width was set to 260 and height was set to 265.
  9. Remove the Cancel button from the dialog box and move the Ok button to the bottom edge of the dialog box.
  10. Select Add Resource from the Project menu and select String Table. Click New to create a new String Table.
  11. Create six resource strings and values as shown below.
    1. IDS_STRING_FONTNAMEFORBENGALI "Vrinda"
    2. IDS_STRING_FONTSIZEFORBENGALI "20"
    3. IDS_STRING_FONTNAMEFORMALAYALAM "Kartika"
    4. IDS_STRING_FONTSIZEFORMALAYALAM "18"
    5. IDS_STRING_FONTNAMEDEFAULT "Arial"
    6. IDS_STRING_FONTSIZEDEFAULT "18"
    7. The numeric ids for the strings will be generated automatically by the resource editor.
    8. At this point save the solution.
    9. Create a new C++ source file.
    10. Type code given in the Listing below.

  12. Save the solution.
  13. Build the solution.
  14. Change the Regional and Language Options in your Control Panel and set the language to Bengali (India) from the Standards and Formats Group in the Regional options Tab.
  15. Run the application
  16. The figure below shows the output of the Calendar application when regional settings are set to Bengali.
    Calendar application Output - Bengali
    The above figure shows the names of the month and days of week in the Bengali language.
  17. Change the Regional and Language Options in your Control Panel and set the language to Malayalam (India) from the Standards and Formats Group in the Regional options Tab.
  18. Run the application.
    The figure below shows the output of the Calendar application when regional settings are set to Malayalam.
    Calendar application Output - Malayalam
    The above figure shows the names of the month and days of week in the Malayalam language.