Could someone give me a bit more information on the difference between Culture
and UICulture
within the .NET framework? What they do and when to use what?
相关问题
- Generic Generics in Managed C++
- How to Debug/Register a Permanent WMI Event Which
- 'System.Threading.ThreadAbortException' in
- Bulk update SQL Server C#
- Should I use static function in c# where many call
Culture
affects how culture-dependent data (dates, currencies, numbers and so on) is presented. Here are a few examples:Culture also affects parsing of user input in the same way:
Beware of cases where the parsing succeeds but the result is not what you would expect it to be.
UICulture
affects which resource file (Resources.lang.resx) is going to be loaded to by your application.So to load German resources (presumably localized text) you would set
UICulture
to the German culture and to display German formatting (without any impact on which resources are loaded) you would setCulture
.Culture and UICulture
Values are pairs of two-letter strings, the first is for defining language and the second for defining the region. Example:
en-GB
hereen
representsEnglish
andGB
representsGreat Briton
en-US
hereen
representsEnglish
andUS
representsUnited States
Use
Culture
for Culture dependent functions like date, time. andUICulture
is for correct resource file loading.Just a small matter to consider in addition to @Vache's awesome explanation: You can set both UICulture and Culture at (page level and application level).
In order to set them at application level, simply add globalization session in web.config
e.g.
<globalization uiCulture="es" culture="es-MX" />
And to set them at the page level, which is good to add on a specific (individual) page, set the Culture and UICulture attributes within @ page directive
e.g.
<%@ Page UICulture="es" Culture="es-MX" %>
The UICulture property might change for each Web browser, whereas the Culture stays constant.
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.