c# : In a dotnet class is there a property that states if the "Current" culture is actual the default culture?
Asked Answered
B

3

7

Is there a property in some class that can tell me if the current culture is actually the default culture.

Similar to how localization works with winforms. It states in a form if the language is default.

lets say if i am in en-US - how can i tell via code if en.US is the actual default?

I need to implement some localization for some XML files which .net doesn't support hence i want to implement my own ...

And do it how winforms works i.e

nameofxml.default.xml (this is the default local)
nameofXml.de-de.xml (this is german) 

etc

does a property exist?

Bromate answered 28/3, 2011 at 16:24 Comment(1)
Default as in "the invariant culture" or default as in "the system locale"?Srinagar
A
3

System.Globalization.CultureInfo.CurrentCulture indicates you system's Control Panel Region settings, while System.Globalization.CultureInfo.CurrentUICulture corresponds to the system's Input UI Language setting (which you can't change unless you have Multilingual User Interface installed).

Therefore you can use the following code snippet to determine the 'default' culture:

using System.Globalization;
// N.B. execute the following line *before* you programmatically change the CurrentCulture
// (if you ever do this, of course)

// Gets the CultureInfo that represents the culture used by the current thread
CultureInfo culture = CultureInfo.CurrentCulture;
string code = culture.IetfLanguageTag; // e.g. "en-US", "de-DE", etc.

Then you can use the code to locate your .xml files.

Airspace answered 28/3, 2011 at 17:26 Comment(0)
Z
2

You can state at the assembly level that the embedded resources are of a specific culture by using the NeutralResourcesLanguageAttribute.

IIRC, this way the resource manager can optimize the process of resource loading if the required culture is the one embedded in the assembly.

Since you are rolling your own implementation for localization I don't know how this can be helpful, but you can use that attribute to indicate that the culture of the XML localization information embedded directly in the assembly is of a specific culture and default to searching satellite assemblies or other custom back store if you find a mismatch between the declared culture in the assembly and the required culture you are looking for.

Zephyr answered 28/3, 2011 at 16:56 Comment(0)
L
0

CultureInfo.CurrentCulture is a static member that "Gets the CultureInfo that represents the culture used by the current thread." It is accessible from any class if you just include the System.Globalization namespace.

Documentation: http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx

Laminous answered 28/3, 2011 at 17:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.