Reputation: 24308
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?
Upvotes: 7
Views: 665
Reputation: 8558
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.
Upvotes: 3
Reputation: 42246
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
Upvotes: 0
Reputation: 57658
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.
Upvotes: 2