How to: Set the Culture and UI Culture for ASP.NET Web Page Globalization
Globalization is the process of designing and developing applications that function for multiple cultures. Localization is the process of customizing your application for a given culture and locale.
In an ASP.NET Web page, you can set to two culture values, the Culture and UICulture properties. The Culture value determines the results of culture-dependent functions, such as the date, number, and currency formatting, and so on. The UICulture value determines which resources are loaded for the page.
The Culture and UICulture properties are set using Internet-standard strings that identify the language (for example, en for English, es for Spanish, and de for German) and culture (for example, US for the United States, GB for Great Britain, MX for Mexico, and DE for Germany). Some examples are en-US for English/United States, en-GB for English/Great Britain, and es-MX for Spanish/Mexico.
The two culture settings do not have to have the same value. Depending on your application, it might be important to set them separately. An example is a Web auction site. The UICulture property might change for each Web browser, whereas the Culture stays constant. Therefore, prices are always displayed in the same currency and formatting.
The Culture value can be set to specific cultures only, such as en-US or en-GB. This prevents the requirement to identify the correct currency symbol to use for en, where en-US and en-GB have different currency symbols.
Users can set the UI culture and culture in their browsers. For example, in Microsoft Internet Explorer, on the Tools menu, users can click Internet Options, on the General tab, click Language, and then set their language preference. If the enableClientBasedCulture attribute of the element in the Web.config file is set to true, ASP.NET can set the UI culture and culture for a Web page automatically, based on the values that are sent by a browser.It is not a best practice to rely exclusively on browser settings to determine the UI culture for a page. Users frequently use browsers that are not set to their preferences (for example, in an Internet cafe). You should provide a method for users to explicitly choose a language or language and culture (CultureInfo name) for the page.
To set the culture and UI culture for an ASP.NET Web page declaratively
To set the UI culture and culture for all pages, add a globalization section to the Web.config file, and then set the uiculture and culture attributes, as shown in the following example:
To set the UI culture and culture for an individual page, set the Culture and UICulture attributes of the directive, as shown in the following example:
To have ASP.NET set the UI culture and culture to the first language that is specified in the current browser settings, set UICulture and Culture to auto. Alternatively, you can set this value to auto:culture_info_name, where culture_info_name is a culture name. For a list of culture names, see CultureInfo. You can make this setting either in the directive or Web.config file.
To set the culture and UI culture for an ASP.NET Web page programmatically
1. Override the InitializeCulture method for the page.
2. In the overridden method, determine which language and culture to set the page to.
The InitializeCulture method is called very early in the page life cycle, before controls are created or properties are set for the page. Therefore, to read values that are passed to the page from controls, you must get them directly from the request using the collection.
3. Set the UI culture and culture in one of the following ways:
Set the Culture and UICulture properties of the page to the language and culture string (for example, en-US). These properties are internal to the page, and can only be used in a page.
Set the CurrentUICulture and CurrentCulture properties of the current thread to the UI culture and culture, respectively. The CurrentUICulture property takes a language and culture information string. To set the CurrentCulture property, you create an instance of the CultureInfo class and call its CreateSpecificCulture method.
The following code example shows an ASP.NET Web page that lets users select their preferred language from a drop-down list. The page imports two namespaces to make it more convenient to work with threading and globalization classes."C#" UICulture="auto" %>
"System.Threading" %>
"System.Globalization" %>
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/13651903/viewspace-1038440/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- How to: Select an Encoding for ASP.NET Web Page GlobalizationEncodingASP.NETWeb
- HTML Layout Guidelines for ASP.NET Web Page GlobalizationHTMLGUIIDEASP.NETWeb
- 開發者驅動文化(Developer Driven Culture)Developer
- 【Google Arts & Culture】2018-09-08週六Go
- NOIP 2012 普及組 複賽 culture 文化之旅
- ASP.NET Web Page Resources OverviewASP.NETWebView
- How to redirect to a specific web page after sign out from Entra IDWeb
- How to: Use Resources to Set Property Values in Web Server ControlsWebServer
- Engineering Culture Podcast:David Hussman與您探討有效產品發現和Dude公式ASTSSM公式
- 未能載入檔案或程式集“System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”Web
- How to set up printers for GUI?GUI
- How to get and set the system socket buffer in AIXAI
- How the web worksWeb
- How to set word-wrap in VSCode?VSCode
- Web Page Marker Pen All In OneWeb
- How to Disable or set SELinux to Permissive mode [ID 457458.1]Linux
- How to use Qt Designed Ui fileQTUI
- WEB UIWebUI
- Globalization Support Parameters in Views (178)View
- Asp.Net Set Http TimeoutASP.NETHTTP
- Understanding How to Set the SQL Server I/O Affinity OptionSQLServer
- How To List All The Named Events Set For A Database [ID 436036.1]Database
- How Users Read on the Web (轉)Web
- Spring Boot Web Error Page處理Spring BootWebError
- web ui 框架WebUI框架
- How to Set Device Name Using UDEV on Oracle Linux 7.1devOracleLinux
- How To List All The Named Events Set For A Database (Doc ID 436036.1)Database
- Assign Shortcut key for ASP.Net Page Using JavascriptASP.NETJavaScript
- How to enable Large Page Feature on AIX-Based Systems [ID 372157.1]AI
- Dweb.page - 通往分散式Web的入口Web分散式
- Web效能優化:What? Why? How?Web優化
- asp.net中Page.ClientScript.RegisterStartupScript用法小結ASP.NETclient
- ASP.NET Page函式呼叫順序及解釋ASP.NET函式
- Java Web UI框架JavaWebUI框架
- [Vue] how to encapsulate second time of ui componentsVueUI
- How to access a remote web service by Camel CXF endpointREMWeb
- C# Asp.Net Set Image Url to byte[]C#ASP.NET
- SAP UI5 Smart control 的 Page Variant ManagementUI