scope of software applications is steadily increasing to the extent that
to develop globalized applications to cater to multiple locales have become
one of the standard design criterions. The ideal design approach for such
applications would be to provide the capability to execute it in multiple
regions with virtually no changes to the code.
the time, effort and hence cost required for customization of the application
to suit to the local regional settings can be drastically reduced. The
.Net framework has a rich set of tools to accommodate this requirement
for creating globalized software applications.
The information that varies in different regions and that need to be changed
in the software application is termed as culture information. Some of
the tasks that are necessary for customizing the culture information in
multiple locales are as below:
Format date and time values based on the culture
Format number values based on the culture
Perform culture-sensitive string comparison
The culture information can be categorized to the types as follows:
Invariant: culture implies the culture category is culture-insensitive.
Unless it is very essential to use this option, it is not suggested to
apply this culture. It is used mostly when there is a need for consistency
of the application across regions.
Neutral: culture is linked with a language and has no relationship to
country or region. If language is the only consideration which rarely
occurs, this option can be used.
Specific: culture considers both language and region for the culture information.
For example, the string, en-US implies language as English
and the region being United States. This is the best option for representing
.Net support for working with culture information
CultureInfo is the class which can be used to retrieve and manipulate
the information about the cultural context of an application. This information
includes name of culture, its writing system, its calendar, language (and
sub-languages, if any), date and number format, country and region, currency
system, etc. The culture related services that it provides are as below:
Control string comparisons
Control number comparisons and formats
Control date comparisons and formats
Control how resources are retrieved and used|
To use this class, the namespace, System.Globalization has to be included.
To get and set the culture information, CurrentCulture property of the
executing threads CurrentThread property is used. Based on this,
the date/time and currency format can be converted accordingly. For this,
there should not be any hard-coded values in the code. Instead, the formatted
value has to be used for getting the right string for display based on
the current culture.
The CurrentUICulture property of the CurrentThread class is used to set
and get the culture information related to the visual aspects of the application.
Unlike the CurrentCulture property, this property should be set only when
the application starts.
The RegionInfo class is another class used to provide more detailed information
about a particular country or region. It is fetched by passing the name
of the CultureInfo object to its constructor while creating the RegionInfo
The DateTimeFormatInfo and NumberFormatInfo classes are used to fetch
the information that differs across cultural boundaries. For example,
the sequence of the days of a week or months of a year can vary from one
country to the other. These differences of information are handled by
the above two classes. The NumberFormatInfo class provides mechanism for
displaying how numbers are represented and displayed while the DateFormatInfo
class takes care of handling dates.
Sometimes, it becomes necessary to compare the same value in two different
cultural contexts. For this, the class, CompareInfo is used. For comparing
such data, firstly, a CompareInfo object instance is created with the
culture that has to be compared with the current culture of the application.
After creating the CompareInfo object instance(with the culture that needs
to be compared with) and by calling the Compare method of the CompareInfo
object with the parameters as two values that need to be compared, the
difference between them will be listed out. Options are provided to specify
the comparison type which include whether case has to be ignored, symbols
(like %, &, etc.) to be ignored, etc.
The .Net framework has included a mechanism to specify a custom culture
which can be used if the existing cultures provided by it are not sufficient
for the user needs. For this, the class, CultureAndRegionInfoBuilder can
be used in two ways. The custom culture can be totally created from scratch
or by re-using the existing one by inheriting it from the parent settings
and incorporate the necessary changes.
It is not only enough to be aware of the usage of the classes for designing
and developing the globalized application but also plan the resource file
efficiently for storing the strings, bitmaps, icons, wav files, etc. which
need to be changed based on the culture. For including the resource files,
the namespace, System.Resources namespace has to be included
Best practices for designing globalized applications:
All strings including the labels (for User Interface controls)
and error messages should not be hard coded.
Lengths of the controls need to be fixed based on the maximum possible
length of the string converted in language other than English
Representation for Decimal separator varies from one region to
the other. This has to be taken care of while designing the User Interface
and string messages, if any.
Date and time representation changes from one country to the other.
The display for such details (like calendar, text box, etc.) in the User
interface needs to accommodate the change.
While designing Keyboard shortcuts, care needs to be taken since
the keyboard layout also depends on the locale. It is suggested to use
the Function keys for shortcuts since they are present in all keyboards.