public static List <LanguageDefinition> GetResourceDictonaries() { string Path = GetAssemblyDirectory(); string ExternalPath = System.IO.Path.Combine(Path, "data", "lang"); List <LanguageDefinition> Languages = AvaliableInternalLanguages; if (!Directory.Exists(ExternalPath)) { return(Languages); } var ExternalLangFolder = new DirectoryInfo(ExternalPath); foreach (var File in ExternalLangFolder.GetFiles("*", SearchOption.TopDirectoryOnly)) { if (File.Extension != ".xaml") { continue; } if (LanguageDefinition.TryPrase(File, out LanguageDefinition ExternalLang)) { Languages.Add(ExternalLang); } } return(Languages); }
private static void LanguageChange(LanguageDefinition definition) { var possible = Application.Current.Resources.MergedDictionaries.Where(x => x is LanguageDictionary).FirstOrDefault(); Application.Current.Resources.MergedDictionaries.Remove(possible); LanguageDictionary dict = new LanguageDictionary(definition); Application.Current.Resources.MergedDictionaries.Add(dict); }
public static bool TryPrase(System.IO.FileInfo fileInfo, out LanguageDefinition definition) { try { ResourceDictionary resourceDictionary = new ResourceDictionary(); resourceDictionary.Source = new Uri(fileInfo.FullName, UriKind.Absolute); if (resourceDictionary.Count == 0 || !fileInfo.Name.StartsWith("lang.")) { definition = null; return(false); } else { string locale = fileInfo.Name.Remove(0, 5).Replace(fileInfo.Extension, ""); definition = new LanguageDefinition(locale, fileInfo.FullName, true); return(true); } } catch { definition = null; return(false); } }
public LanguageDictionary(LanguageDefinition language) { this.Langauge = language.Locale; this.Source = new Uri(language.Path, (language.IsExternal ? UriKind.Absolute : UriKind.Relative)); }