/// <summary> /// Gets the values. /// </summary> /// <owner>Anton Patron</owner> /// <returns>The text values.</returns> private async Task <Dictionary <string, string> > GetResourceFileValuesAsync() { var optionsInstance = await GeneralOptions.GetLiveInstanceAsync().ConfigureAwait(false); var manager = ResourceManager.CreateFileBasedResourceManager(optionsInstance.OptionResourceFile, optionsInstance.OptionResourceDirectoryPath, null); return(TranslatorProviderTextId.GetTextvalues(manager, new CultureInfo(optionsInstance.LaunguageId), true). GroupBy(textItem => textItem.textId). ToDictionary(textItem => textItem.Key.ToString(), textItem => textItem.First().text)); }
/// <summary> /// Returns a sequence of text cluster id values for texts that match the search words. /// </summary> /// <owner>Anton Patron</owner> /// <param name="language">The <see cref="CultureInfo"/> specifying the language to search.</param> /// <param name="includeParentCultures">The value indicating if the result should include the parent languages.</param> /// <returns>A sequence of text cluster id values for texts that match the search words.</returns> private static List <(int textId, string text)> GetTextvalues(ResourceManager resourceManager, CultureInfo language, bool includeParentCultures) { // // Include parent cultures if specified. // List <(int textId, string text)> result = new List <(int textId, string text)>(); if (includeParentCultures && language.Parent != null && !language.IsNeutralCulture) { // // Call this method recursively to access text clusters registered on parent cultures. // result.AddRange(TranslatorProviderTextId.GetTextvalues(resourceManager, language.Parent, true)); } // // Get all the text clusters registered on this culture. // using (ResourceSet resources = resourceManager.GetResourceSet(language, true, false)) { if (resources == null) { return(result); } // // Find matches to the search words. // foreach (DictionaryEntry item in resources) { string text = item.Value as string; if (!(item.Key is string id) || text == null) { continue; } // // remove hotkey character. // text = text.Replace("&", string.Empty).Trim(); result.Add((Convert.ToInt32(id.Replace("ID", string.Empty)), text)); } return(result); } }