/// <summary> /// Scaning for language dictionaries in XAML files stored into the shared directory, /// and loading them to Merged dictionaries. /// Loading only relative to the new culture if found. Leave a previous culture if not. /// /// Require files format: *.lang.CULTURE_CODE.xaml, where culture code equal current translation of the app. /// Example: plugin.feed.lang.en-US.xaml /// </summary> /// <param name="path">Path to directory with dictionaries.</param> /// <param name="culturesOrder">Array of cultures reuested to loading in the priiority oreder.</param> public static void LoadDictionaries(string path, params CultureInfo[] culturesOrder) { #region Validate and fix base conditions // Validate directory. if (!Directory.Exists(path)) { Directory.CreateDirectory(path); Console.WriteLine("PLUGINS DIRECTORY NOT FOUND. NEW ONE WAS CREATED."); } #endregion // Getting the keys. string[] cutureKeys = new string[culturesOrder.Length]; for (int i = 0; i < culturesOrder.Length; i++) { CultureInfo info = culturesOrder[i]; cutureKeys[i] = info.Name; } // Request dictionaries update. Dictionaries.API.UpdateDictionariesGroup(path, "lang", cutureKeys); // Update culture. System.Threading.Thread.CurrentThread.CurrentUICulture = culturesOrder[0]; // Inform subscribers. LanguagesDictionariesUpdated?.Invoke(); }
/// <summary> /// Unloading all current loaded localization dictionaries. /// </summary> public static void UnloadDictionaries() { // Clearing current loaded dicts. Dictionaries.API.ClearDictionariesGroup("lang"); // Inform subscribers. LanguagesDictionariesUpdated?.Invoke(); }
/// <summary> /// Scaning for language dictionaries in XAML files, and load them to Merged dictionaries. /// Load relative to new culture if found. Leave previous culture if not. /// /// Require files format: *.lang.CULTURE_CODE.xaml, where culture code equal current translation of the app. /// Example: plugin.feed.lang.en-US.xaml /// </summary> /// <param name="targetCulture">Culture that will be serched with hightest priority.</param> /// <param name="secondaryCulture">Culture that will be prefured in case of target not implemented. If also not implemented than will be used first entry.</param> public static void LoadXAML_LangDicts(CultureInfo targetCulture, CultureInfo secondaryCulture) { #region Validate and fix base conditions // Validate directory. if (!Directory.Exists(Plugins.Constants.PLUGINS_DIR)) { Directory.CreateDirectory(Plugins.Constants.PLUGINS_DIR); Console.WriteLine("PLUGINS DIRECTORY NOT FOUND. NEW ONE WAS CREATED."); } #endregion // Request dictionaries update. UpdateDictionariesGroup(Plugins.Constants.PLUGINS_DIR, "lang", targetCulture.Name, secondaryCulture.Name); // Update culture. System.Threading.Thread.CurrentThread.CurrentUICulture = targetCulture; // Inform subscribers. LanguagesDictionariesUpdated?.Invoke(); }