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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【Google Arts & Culture】2018-09-08週六Go
- How to redirect to a specific web page after sign out from Entra IDWeb
- How to set word-wrap in VSCode?VSCode
- 2024年教育、管理與藝術文化國際學術會議 (EMAC 2024) 2024 International Conference on Education, Management and Art and CultureMac
- How to use Qt Designed Ui fileQTUI
- [Vue] how to encapsulate second time of ui componentsVueUI
- Web Page Marker Pen All In OneWeb
- [20190522]How to get dump or list parameters set at session level.txtSession
- WEB UIWebUI
- SAP UI5 Smart control 的 Page Variant ManagementUI
- web ui 框架WebUI框架
- asp.net core 整合swagger uiASP.NETSwaggerUI
- Dweb.page - 通往分散式Web的入口Web分散式
- Java Web UI框架JavaWebUI框架
- YLazy Web Page Test , 網頁效能測試平臺Web網頁
- How to describe the main content of the web novel "龍藏" in about 50 English words?AIWeb
- Web 開發學習筆記(5) — 抽象出 Page 類Web筆記抽象
- iOS開發UI第三方庫-小紅點&pageiOSUI
- ASP.NET Core Web API 介面限流ASP.NETWebAPI
- ASP.NET Web Forms – 事件簡介ASP.NETWebORM事件
- ASP.NET Web Pages – 物件簡介ASP.NETWeb物件
- ASP.NET Core Web API 與 SSLASP.NETWebAPI
- Windows 部署 Stable Diffusion web UIWindowsWebUI
- 時區提示:Local time zone must be set--see zic manual page 2018的解決辦法
- SAP UI5 初學者教程之十一 :SAP UI5 容器類控制元件 Page 和 PanelUI控制元件
- ASP.NET Web Forms – ArrayList 物件簡介ASP.NETWebORM物件
- ASP.NET Web Forms – SortedList 物件簡介ASP.NETWebORM物件
- ASP.NET Web Forms – Hashtable 物件簡介ASP.NETWebORM物件
- ASP.NET Web Forms – 導航簡介ASP.NETWebORM
- ASP.NET Core Web API 教程 - Project ConfigurationASP.NETWebAPIProject
- ASP.NET Core Web Api之JWT(一)ASP.NETWebAPIJWT
- ASP.NET Core Web API中使用SwaggerASP.NETWebAPISwagger
- 讓ASP.NET Web API的Action方法ASP.NETWebAPI
- ASP.NET Core Web API 整合測試ASP.NETWebAPI
- ASP.NET Web Forms – Web 伺服器控制元件簡介ASP.NETWebORM伺服器控制元件
- 翻譯 - ASP.NET Core 基本知識 - Web 主機 (Web Host)ASP.NETWeb
- Dynamics 365 Web API Set Values of all Data Types using Web API in Dynamics CRM Through C#WebAPIC#
- 使用 ASP.NET Core 和 MongoDB 建立 Web APIASP.NETMongoDBWebAPI
- ASP.NET Web Forms – XML 檔案簡介ASP.NETWebORMXML