using System; using System.Collections.Generic; using System.Windows; using System.Windows.Threading; using Cvte.EasiNote; using Cvte.Windows.Localization; namespace BetterEN5 { static class UIItemManagerExtensions { public static void AppendWithLang(this IUIItemManager manager, UIItem item, UIItemAttribute attribute, IList langInfoList) { manager.Append(c => item, attribute); var purpose = attribute.Purposes[0]; string menuName; if (purpose == UIItemPurposes.BoardEditMenu) { menuName = "BoardEditContextMenu"; } else if (purpose == UIItemPurposes.HeadToolBar) { menuName = "HeadToolBar"; } else { menuName = purpose.Replace(".", "_"); } var itemLangKey = item.GetType().Name.Replace("MenuItem", "").Replace("HeadToolBar", "").Replace("ApplicationMenu", "").Replace("ExtendedTitleBar", ""); var langKey = $"Lang.{menuName}.{itemLangKey}"; Application.Current.Dispatcher.InvokeAsync(() => { foreach (var langInfo in langInfoList) { Lang.Sources.Add(new DictionaryLanguageSource { [langInfo.CultureInfo] = new Dictionary() { { langKey, langInfo.LangText }, }, }); } }, DispatcherPriority.Send); } } }