Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 282
Martin Avatar asked Mar 28 '11 16:03

Martin


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.


2 Answers

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.

like image 177
Igor Korkhov Avatar answered Sep 29 '22 04:09

Igor Korkhov


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.

like image 27
João Angelo Avatar answered Sep 29 '22 03:09

João Angelo