Incorporating Globalization
In our sample website, after creating the resource files and creating some localized data, we first start using the explicit localization to set the text of the controls such as the Labels
in our web site so that they get their values from the resource files. Because in our example there are four languages, let us create four resource files, along with a fifth fallback resource file (with no locale name). Here is a screenshot of these files:
Note that the resource files have the locale as their middle names, so we need to set the UICulture
to the same named locale so that ASP.NET can access these resource files.
But the problem is, how do we change the culture dynamically on the postback event? Fortunately, ASP.NET provides a method in the Page
class to override InitializeCulture()
. This method executes very early in the page life cycle (much before any control is generated), and here we can set the UICulture
and Culture
of the current thread.
Because this method...