/// <summary>
/// Sets the UI language
/// </summary>
/// <param name="culture">Language code (ex. "en-EN")</param>
/// <param name="filename">The file to load the resources from</param>
public void SelectCulture(String culture, String filename)
{
if (culture == ":null:")
{
culture = CultureInfo.InstalledUICulture.Name;
}
// List all our resources
var dictionaryList = new List <ResourceDictionary>(Current.Resources.MergedDictionaries);
var resourceDictionary = Utilities.Load(filename);
if (resourceDictionary == null)
{
// if not found, then try from the application's resources
String requestedCulture = $"Locale.{culture}.xaml";
resourceDictionary = dictionaryList.FirstOrDefault(d => d.Source.OriginalString == "/BetterExplorer;component/Translation/" + requestedCulture);
if (resourceDictionary == null)
{
// If not found, we select our default language
requestedCulture = "DefaultLocale.xaml";
resourceDictionary = dictionaryList.FirstOrDefault(d => d.Source.OriginalString == "/BetterExplorer;component/Translation/" + requestedCulture);
}
}
// If we have the requested resource, remove it from the list and place at the end.\
// Then this language will be our string table to use.
if (resourceDictionary != null)
{
try {
Current.Resources.MergedDictionaries.Remove(resourceDictionary);
}
catch {
}
Current.Resources.MergedDictionaries.Add(resourceDictionary);
}
// Inform the threads of the new culture
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
}