public static void LocalizeListBox(ListBox lb, int fromIndex = 0, int?toIndex = null, bool reverse = false)
        {
            var items         = lb.Items.Cast <DdlItem>().ToArray();
            var selectedItems = lb.SelectedItems();

            lb.ItemsSource = null;
            var itemTexts = LocalizedStrings.Single(ls => ls.Key.AfterFirst("_") == "ListBox_Items_" + lb.Name).Value.Split(",", false, StringSplitOptions.None);

            if (reverse)
            {
                items = items.Reverse().ToArray();
            }
            for (var i = fromIndex; i < (toIndex ?? items.Length); i++)
            {
                if (!String.IsNullOrEmpty(itemTexts[i]))
                {
                    items[i].Text = itemTexts[i];
                }
            }
            if (reverse)
            {
                items = items.Reverse().ToArray();
            }
            lb.ItemsSource = items;
            lb.SelectByItems(selectedItems);
        }
        public static void LocalizeDataGridHeaders(DataGrid dg)
        {
            var headers = LocalizedStrings.Single(ls => ls.Key.AfterFirst("_") == "DataGrid_Headers_" + dg.Name).Value.Split(",", false, StringSplitOptions.None);

            for (var i = 0; i < dg.Columns.Count; i++)
            {
                dg.Columns[i].Header = headers[i];
            }
        }
        public static void LocalizeTag(FrameworkElement fe)
        {
            var isEmptyTextBox = fe is TextBox txtB && txtB.IsNullWhitespaceOrTag();

            fe.Tag = LocalizedStrings.Single(ls => ls.Key.AfterFirst("_") == "Tag_" + fe.Name).Value;
            if (isEmptyTextBox)
            {
                ((TextBox)fe).ResetValue(true); // force because localized placeholder is different than the previous one
            }
        }
        public static void LocalizeContextMenu(FrameworkElement fe)
        {
            var cm        = fe.ContextMenu();
            var itemTexts = LocalizedStrings.Single(ls => ls.Key.AfterFirst("_") == "ContextMenu_Items_" + cm.Control.Name).Value.Split(",", false, StringSplitOptions.None);

            for (var i = 0; i < cm.Items.Count; i++)
            {
                var cmi = cm.Items[i];
                cmi.Text = itemTexts[i];
                cmi.Recreate();
            }
        }
        public static void LocalizeContextMenus <T>() where T : FrameworkElement
        {
            var menusForType = ContextMenusManager.ContextMenus.Where(kvp => kvp.Key is T).Select(kvp => kvp.Value).ToArray();
            var itemTexts    = LocalizedStrings.Single(ls => ls.Key.AfterFirst("_") == "ContextMenu_Items_" + typeof(T).Name).Value.Split(",", false, StringSplitOptions.None);

            foreach (var cm in menusForType)
            {
                for (var i = 0; i < cm.Items.Count; i++)
                {
                    cm.Items[i].Text = itemTexts[i];
                    cm.Items[i].Recreate();
                }
            }
        }
        public static void LocalizeDropdown(ComboBox ddl)
        {
            var eventHandlers = ddl.RemoveEventHandlers(nameof(ddl.SelectionChanged));

            var items        = ddl.Items.Cast <DdlItem>().ToArray();
            var selectedItem = ddl.SelectedItem();

            ddl.ItemsSource = null;
            var itemTexts = LocalizedStrings.Single(ls => ls.Key.AfterFirst("_") == "ComboBox_Items_" + ddl.Name).Value.Split(",", false, StringSplitOptions.None);

            for (var i = 0; i < items.Length; i++)
            {
                if (!String.IsNullOrEmpty(itemTexts[i]))
                {
                    items[i].Text = itemTexts[i];
                }
            }
            ddl.ItemsSource = items;
            ddl.SelectByItem(selectedItem);

            ddl.AddEventHandlers(nameof(ddl.SelectionChanged), eventHandlers);
        }
 public static string GetDisciplineTypeLocalizedString(DisciplineType?discipline)
 {
     return(IsInitialized ? LocalizedStrings.Single(ls => ls.Key.AfterFirst("_") == "DisciplineType_" + discipline.EnumToString()).Value : null);
 }
 public static string GetGeneralLoaderLocalizedString()
 {
     return(LocalizedStrings.Single(ls => ls.Key.AfterFirst("_") == "Loader_General").Value);
 }
 public static string[] GetProfitByPeriodStatisticsLocalizedStrings()
 {
     return(LocalizedStrings.Single(ls => ls.Key.AfterFirst("_") == "ProfitByPeriodStatistics").Value.Split(","));
 }
 public static string[] GetGeneralStatisticsLocalizedStrings()
 {
     return(LocalizedStrings.Single(ls => ls.Key.AfterFirst("_") == "GeneralStatistics").Value.Split(","));
 }
 public static void LocalizeRadioButton(RadioButton rb)
 {
     rb.Content = LocalizedStrings.Single(ls => ls.Key.AfterFirst("_") == "RadioButton_" + rb.Name).Value;
 }
 public static void LocalizeTextBlock(TextBlock tb)
 {
     tb.Text = LocalizedStrings.Single(ls => ls.Key.AfterFirst("_") == "TextBlock_" + tb.Name).Value;
 }
        public static void LocalizeTile(Tile tile)
        {
            var tb = tile.VisualDescendants <TextBlock>().Single(t => !string.IsNullOrWhiteSpace(t.Text));

            tb.Text = LocalizedStrings.Single(ls => ls.Key.AfterFirst("_") == "Tile_" + tile.Name).Value;
        }
 public static void LocalizeWatermark(FrameworkElement fe)
 {
     fe.SetValue(TextBoxHelper.WatermarkProperty, LocalizedStrings.Single(ls => ls.Key.AfterFirst("_") == "Watermark_" + fe.Name).Value);
 }
 public static void LocalizeCheckBox(CheckBox cb)
 {
     cb.Content = LocalizedStrings.Single(ls => ls.Key.AfterFirst("_") == "CheckBox_" + cb.Name).Value;
 }
 public static void LocalizeTooltip(FrameworkElement fe)
 {
     fe.ToolTip = LocalizedStrings.Single(ls => ls.Key.AfterFirst("_") == "Tooltip_" + fe.Name).Value;
 }
 public static void LocalizeButton(Button btn)
 {
     btn.Content = LocalizedStrings.Single(ls => ls.Key.AfterFirst("_") == "Button_" + btn.Name).Value;
 }
 public static void LocalizeLabel(Label lbl)
 {
     lbl.Content = LocalizedStrings.Single(ls => ls.Key.AfterFirst("_") == "Label_" + lbl.Name).Value;
 }