DCSIMG
How to Specify Specific Language for Localization - Leon

Leon

How to Specify Specific Language for Localization

ASP.NET 2.0 infrastructure uses provider architecture in conjunction with local and global resources to support localization. Provider architecture gives us option to replace default resx (XML) resources, used to store localized data, with anything else (database for example). Global resources provide us with auto-generated, strongly-typed API to access application wide resources. Local resources can use implicit and explicit binding and have nice “Generate Local Resource” (Tools>Generate Local Resource in Visual Studion) option to generate default resource file for current page and inject implicit binding. See Web Pages Resources Overview in MSDN for more.

Localization provider uses current culture information to select appropriate resources to be served. How can we specify language to be used? We have couple of choices:

  • As I already mentioned, by default, localization provider will use current thread culture information. This culture determined by request header Accept-Language. Value of this header is set by browser. For example, in IE accepted languages could be configured through Tools>Internet Options…>Languages. It is not a very user friendly option, especially in multilingual country like ours.
  • In case no specific language was specified by browser, default culture can be set in Web.Config file, in globalization element.

    <globalization uiCulture="he" />

  • At the page level, you can set culture in <@ Page pragma in aspx file. This definition will supersede those sent by browser and defined in Web.Config.

    <%@ Page Language="C#" UICulture="ru"

  • Finally, culture can be set in codebehind: All subsequent calls to resource related API (GetLocalResourceObject, GetGlobalResourceObject) will be affected. Here is the catch: to influence implicitly bounded (using meta:resourcekey) to local resources attributes, you have to set uiculture in InitializeCulture page method override.

    protected override void InitializeCulture()
    {
          this.UICulture = "he";
    }

    Culture, set in code will override all previous definitions.
פורסם: Aug 01 2007, 11:47 PM by Leon Langleyben | with no comments
תגים:
שלח תגובה

(שדה חובה)  

(שדה חובה)  

(אופציונלי)

(שדה חובה) 

Please add 1 and 4 and type the answer here:


Enter the numbers above: