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.
- Create a new project and select Win32 Project under Visual C++ Projects from Visual Studio.NET.
- Enter the project name you wish in the New Project dialog box.
- Allow the default settings in the Win32 Application Wizard and Select Empty Project option under Additional Options as shown in the figure below.
- Click Finish.
- From the Project menu select Project Properties item, the Project Property Pages Dialog Box appears as shown below.
- Select Use Unicode Character Set in the Character Set as shown in the above figure.
- Select Add Resource from the Project menu and select Dialog. Click New to create a new Dialog resource.
- 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.
- Remove the Cancel button from the dialog box and move the Ok button to the bottom edge of the dialog box.
- Select Add Resource from the Project menu and select String Table. Click New to create a new String Table.
- Create six resource strings and values as shown below.
- IDS_STRING_FONTNAMEFORBENGALI "Vrinda"
- IDS_STRING_FONTSIZEFORBENGALI "20"
- IDS_STRING_FONTNAMEFORMALAYALAM "Kartika"
- IDS_STRING_FONTSIZEFORMALAYALAM "18"
- IDS_STRING_FONTNAMEDEFAULT "Arial"
- IDS_STRING_FONTSIZEDEFAULT "18"
- The numeric ids for the strings will be generated automatically by the resource editor.
- At this point save the solution.
- Create a new C++ source file.
- Type code given in the Listing below.
1. /**
2. * calendar.cpp
3. * 12-August-2004
4. * This program will display calendar's month and days in localized
5. * language that is chosen from regional setting.
6. */
7.
- Save the solution.
- Build the solution.
- 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.
- Run the application
- The figure below shows the output of the Calendar application when regional settings are set to Bengali.
The above figure shows the names of the month and days of week in the Bengali language.
- 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.
- Run the application.
The figure below shows the output of the Calendar application when regional settings are set to Malayalam.
The above figure shows the names of the month and days of week in the Malayalam language.
Displaying the Current Date and Time using Current Locale Information
These constants are used with functions such as GetDateFormat() and GetTimeFormat() to obtain the date and time format associated with the default user or the system.
Repeat steps 1 to 13 as described for the Calendar application. However, the size of dialog box is modified for this application, the height is set to 130 and width is set to 280.
Type code given in the Listing below.
1. /**
2. * dateonly.cpp
3. * 13-August-2004;
4. *
5. * This program display the localized date and time.
6.
7. * To run the program set the "Character set" as "Use Unicode Character Set"
8. * on the project properties setting.
9. */
Save the solution.
Build the solution.
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.
Run the application.
The figure below shows the output of the Date and Time application when regional settings are set to Bengali.

The above figure shows the Date and Time in the Bengali language.
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.
Run the application.
The figure below shows the output of the Date and Time application when regional settings are set to Malayalam.

The above figure shows the Date and Time in the Malayalam language.
Displaying Numbers and Currency using the Current Locale Information
The GetCurrencyFormat(), and GetNumberFormat()functions are used to obtain the current currency information and number format. The GetLocaleInfoW() function is used to obtain the native numbers or the Arabic numerals as represented using the default language of the locale. The code below shows how to use these functions to work with the currency and native number format.
Repeat steps 1 to 7 as described in the calendar application
Change the size of the dialog box and set its height and width in the dialog editor. In this example width was set to 225 and height was set to 375.
Remove the Ok and Cancel buttons from the dialog box.
Add a Group Box control to the dialog box. The x and y positions of the group box is set to 7 and 85 respectively. The width and height of the group is set to 300 and 90 respectively. Change the caption of the group box to Number Conversion
Place a two Static Text controls within the group box towards the left of the group box.
The text of the first static text is set to Enter a Number.
The text of the second static text is set to Converted Result.
Place a Text Box control adjacent to the first label. Provide the control id as IDC_SOURCENUMBER in the id property of the text box.
Place a Static Text control adjacent to the second label. Provide the control id as IDC_RESULTNUMBER in the id property of this control.
Add two Button controls to the group box.
Provide the Caption Convert and Exit to the buttons respectively. The id property of the Convert button is set to IDC_CONVERT and the id property of Exit button is set to IDOK.
Select Add Resource from the Project menu and select String Table. Click New to create a new String Table.
Create six resource strings and values as shown below.
- IDS_STRING_FONTNAMEFORBENGALI "Vrinda"
- IDS_STRING_FONTSIZEFORBENGALI "20"
- IDS_STRING_FONTNAMEFORMALAYALAM "Kartika"
- IDS_STRING_FONTSIZEFORMALAYALAM "18"
- IDS_STRING_FONTNAMEDEFAULT "Arial"
- IDS_STRING_FONTSIZEDEFAULT "18"
The numeric ids for the strings will be generated automatically by the resource editor.
At this point save the solution.
Create a new C++ source file.
Type code given in the Listing below.
1. /**
2. * NumberCurrency.cpp
3. * 13-August-2004;
4. *
5. * This program display the localized numbers and currency.
6. * And it will convert user specified ASCII numbers to
7. * native number format.
8. *
9. * To run the program set the "Character set" as "Use Unicode Character Set"
10. * on the project properties setting.
11. */
Save the solution.
Build the solution.
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.
Run the application.
The figure below shows the output of the Number and Currency application when regional settings are set to Bengali.

In the Enter a Number text box type 233.57, the number is displayed in native format as shown in the figure below.

The above figure shows the number format converted to Bengali.

The above figure shows the number format converted to Malayalam.
Sorting Natural Language Strings using Current Locale Information.
The sort order of every natural language is different. Therefore every locale and culture will have its own sorting order. Sorting based on the default ordering scheme of a locale is known as collation. The CompareString() function takes two locale specific strings along with the current locale and returns which of the two given strings are greater. Using this function is similar to using the other comparison functions in C. The semantics of this method is also similar to the comparison routines such as strcmp. The code below shows how to use the CompareString() function to determine the ordering of strings in a locale specific manner.
Repeat steps 1 to 7 as described in the calendar application.
Change the size of the dialog box and set its height and width in the dialog editor. In this example width was set to 275 and height was set to 200.
Remove the Ok and Cancel buttons from the dialog box.
Place a Static Text control at the top of the dialog box and set the text to Compare Two Unicode Strings.
Place a Static Text control towards the left of dialog box and set the text to First String.
Place another Static Text control towards the left of dialog box and set the text to Second String.
Place a Text Box control adjacent to the first static text control. Provide the control id as IDC_STRING1 in the id property of the text box.
Place a Text Box control adjacent to the second label. Provide the control id as IDC_STRING2 in the id property of this control.
Place two more Static Text controls one next to the other. Set the text on the static text control which is towards the left to Result.
Set the control id for the second static text as IDC_RESULT in the id property.
Add two Button controls.
Provide the Caption Compare and Exit to the buttons respectively. The id property of the Compare button is set to IDC_COMPARE and the id property of Exit button is set to IDOK.
Select Add Resource from the Project menu and select String Table. Click New to create a new String Table.
Create six resource strings and values as shown below.
- IDS_STRING_FONTNAMEFORBENGALI "Vrinda"
- IDS_STRING_FONTSIZEFORBENGALI "20"
- IDS_STRING_FONTNAMEFORMALAYALAM "Kartika"
- IDS_STRING_FONTSIZEFORMALAYALAM "18"
- IDS_STRING_FONTNAMEDEFAULT "Arial"
- IDS_STRING_FONTSIZEDEFAULT "18"
The numeric ids for the strings will be generated automatically by the resource editor.
At this point save the solution Create a new C++ source file.
Type code given in the Listing below.
1. /**
2. * Collation.cpp
3. * 12-August-2004;
4. *
5. * This program compares two UNICODE localized string, and gives the
6. * result of the comparison
7. *
8. * To run the program set the "Character set" as "Use Unicode Character Set"
9. * on the project properties setting.
10. */
11.
Save the solution.
Build the solution.
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.
Run the application.
The figure below shows the output of the Collation application when regional settings are set to Bengali.

Set the input language to Bengali in the Language bar.
In the First String Text Box type the following name কার্তিকেযন.
In the Second String Text Box type the following name রমেষ.
Click Compare. The result is shown in the figure below.

Set the input language to Malayalam in the Language bar.
In the First String Text Box type the following name കാ൪തിേകയ൯.
In the Second String Text Box type the following name രമേഷ്.
Click Compare. The result is shown in the figure below.

Using Resource Strings in Programs
Along with these resources that are localizable one should also handle text messages that are a part of the application. In the following application all strings are written a string table that is maintained in an .rc file. You must edit the .rc file from outside the Visual Studio editor to enter Unicode strings. This is because the editor may not support entering such characters.
Repeat steps 1 to 7 as described in the calendar application.
Change the size of the dialog box and set its height and width in the dialog editor. In this example width was set to 275 and height was set to 200.
Remove the Ok and Cancel buttons from the dialog box.
Place a Static Text control at the top of the dialog box and set the text to empty. Provide the control id as IDC_NAME in the id property of the static text box.
Place a Text Box control below the static text control. Provide the control id as IDC_RESULT in the id property of the text box.
Add two Button controls.
Provide an Empty Caption to the buttons. The id property of the first button is set to IDC_YES and the id property of second button is set to IDC_NO.
Select Add Resource from the Project menu and select String Table. Click New to create a new String Table.
Add the following to the String table.
- IDS_STRING_TITLE1 "Enter your name"
- IDS_STRING_YES1 "YES"
- IDS_STRING_NO1 "NO"
- IDS_STRING_WELCOME1 "Welcome"
- IDS_STRING_FONTNAMEFORBENGALI "Vrinda"
- IDS_STRING_FONTSIZEFORBENGALI "20"
- IDS_STRING_FONTNAMEFORMALAYALAM "Kartika"
- IDS_STRING_FONTSIZEFORMALAYALAM "18"
- IDS_STRING_FONTNAMEDEFAULT "Arial"
- IDS_STRING_FONTSIZEDEFAULT "18"
The numeric ids for the strings will be generated automatically by the resource editor.
At this point save the solution.
Close the solution at this point and open the .rc file using Notepad.
Edit the .rc file and add the following content to the string table.
- IDS_STRING_TITLE3 "আফ্নি নাম কি?"
- IDS_STRING_YES3 "হা থবা"
- IDS_STRING_NO3 "না"
- IDS_STRING_WELCOME3 "স্বাগতম"
- IDS_STRING_TITLE2 "നിങ്ളുടെ പേര് എന്താണ്?"
- IDS_STRING_YES2 "അതെ"
- IDS_STRING_NO2 "അല്ല"
- IDS_STRING_WELCOME2 "സ്വാഗതം"
Once edited, your code in notepad will be as shown in the figure below.

Click Save As and change the encoding format to Unicode in the Save As dialog box of notepad. Overwrite the .rc file.
Create a new C++ source file.
Type code given in the Listing below.
1. /**
2. * infoDisp.cpp
3. * 13-August-2004;
4. *
5. * This program get the name of the user in locale language
6. * and display welcome message in the same locale language.
7. *
8. * To run the program set the "Character set" as "Use Unicode Character Set"
9. * on the project properties setting.
10. */
Open the solution once again in Visual Studio and Build the application.
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.
Right Click on the Desktop and select Properties. Select Appearance tab in the Display Properties Dialog Box and click Advanced.
In the dialog box that is displayed select Message Box in the Item, Drop-Down List and set the size to 20. Click Ok and Apply changes to the Display Properties.
Run the application.
The figure below shows the output of the InfoDisp application when regional settings are set to Bengali.

Type the name কার্তিকেযন in the Text Box. The figure below shows the Dialog box after the text is entered.

Click the button with the caption হা থবা. The figure below shows the output.

The figure below shows the output of the InfoDisp application when regional settings are set to Malayalam.

Type the name in the രമേഷ് Text Box. The figure below shows the Dialog box after the text is entered.

Click the button with the caption അതെ. The figure below shows the output.
