public void SetCulture(string newSource) { try { ResourceDictionary langOld = Root.Single(p => p.Source.OriginalString.Contains("Strings.")); if (langOld != null) { ResourceDictionary lang = LoadDictionary(newSource); if (lang != null) { Application.Current.Resources.BeginInit(); Root.Remove(langOld); Root.Insert(0, lang); Application.Current.Resources.EndInit(); LanguageDictionary = lang; } } } catch (Exception e) { BusinessLogger.Manage(e); throw; } }
private ResourceDictionary LoadDictionary(string source) { Stream streamInfo = null; ResourceDictionary dictionary = null; try { streamInfo = DistantManager.Instance.GetResource(source); if (streamInfo != null) { Uri baseUri = DistantManager.Instance.GetUri(source); dictionary = XamlReader.Load(streamInfo) as ResourceDictionary; dictionary.Source = baseUri; } } catch (Exception e) { BusinessLogger.Manage(e); return(null); } return(dictionary); }
/// <summary> /// Gets a string from the common resource file. /// </summary> /// <param name="key">The key.of the desired string.</param> /// <returns>The string corresponding to the key provided.</returns> public string GetString(string key) { try { string value = LanguageDictionary[key] as string; if (value == null || value.Contains("String.Empty")) { value = string.Empty; } return(value); } catch (Exception e) { BusinessLogger.Manage(e); return(string.Empty); } }