Mono. Нет перевода на русский язык у SaveFileDialog

Я пытаюсь откомпилировать на mono программку написанную на framework.net 4.8, но получаю проблемы с файловыми диалогами - они отображаются на английском. Я даже попробовал явно указать CultureInfo:

System.Globalization.CultureInfo.CurrentCulture = new System.Globalization.CultureInfo("ru-RU");
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("ru");
var sd = new SaveFileDialog
{
    OverwritePrompt = false,
    AddExtension = true,
    Filter = MiscResources.FileTypeJpeg + @"|*.jpg;*.jpeg|" +
             MiscResources.FileTypePng + @"|*.png|" +
             MiscResources.FileTypeTiff + @"|*.tiff;*.tif"
};
sd.ShowDialog()

Но это ничего не дало: SaveFileDialog

Есть ли какая-либо возможность локализовать SaveFileDialog? Пусть даже вручную.


Ответы (1 шт):

Автор решения: noirhor

Благодаря подсказке Blackmeser, получилось более-менее перевести через System.Reflection

void TranslateDialog(SaveFileDialog d)
        {
            try
            {
                d.Title = "Сохранить как";
                Type mainType = typeof(FileDialog);
                var bindingFlags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance;
               
                ((Button)mainType.GetField("openSaveButton", bindingFlags).GetValue(d)).Text = "Сохранить";
                ((Button)mainType.GetField("cancelButton", bindingFlags).GetValue(d)).Text = "Отмена";
                ((Label)mainType.GetField("searchSaveLabel", bindingFlags).GetValue(d)).Text = "Сохранить в:";
                ((Label)mainType.GetField("fileTypeLabel", bindingFlags).GetValue(d)).Text = "Тип файла:";
                ((Label)mainType.GetField("fileNameLabel", bindingFlags).GetValue(d)).Text = "Имя файла:";
                
                var popupButtonPanel = mainType.GetField("popupButtonPanel", bindingFlags).GetValue(d);
                ((Control)popupButtonPanel.GetType().GetField("recentlyusedButton", bindingFlags).GetValue(popupButtonPanel)).Text = "Недавние";
                ((Control)popupButtonPanel.GetType().GetField("desktopButton", bindingFlags).GetValue(popupButtonPanel)).Text = "Рабочий стол";
                ((Control)popupButtonPanel.GetType().GetField("personalButton", bindingFlags).GetValue(popupButtonPanel)).Text = "Домашняя";
                ((Control)popupButtonPanel.GetType().GetField("mycomputerButton", bindingFlags).GetValue(popupButtonPanel)).Text = "Компьютер";
                ((Control)popupButtonPanel.GetType().GetField("networkButton", bindingFlags).GetValue(popupButtonPanel)).Text = "Сеть";

                var dirComboBox = mainType.GetField("dirComboBox", bindingFlags).GetValue(d);
                var comboBoxItem = dirComboBox.GetType().GetField("recentlyUsedDirComboboxItem", bindingFlags).GetValue(dirComboBox);
                comboBoxItem.GetType().GetField("name", bindingFlags).SetValue(comboBoxItem, "Недавние");
                comboBoxItem = dirComboBox.GetType().GetField("desktopDirComboboxItem", bindingFlags).GetValue(dirComboBox);
                comboBoxItem.GetType().GetField("name", bindingFlags).SetValue(comboBoxItem, "Рабочий стол");
                comboBoxItem = dirComboBox.GetType().GetField("personalDirComboboxItem", bindingFlags).GetValue(dirComboBox);
                comboBoxItem.GetType().GetField("name", bindingFlags).SetValue(comboBoxItem, "Домашняя");
                comboBoxItem = dirComboBox.GetType().GetField("myComputerDirComboboxItem", bindingFlags).GetValue(dirComboBox);
                comboBoxItem.GetType().GetField("name", bindingFlags).SetValue(comboBoxItem, "Компьютер");
                comboBoxItem = dirComboBox.GetType().GetField("networkDirComboboxItem", bindingFlags).GetValue(dirComboBox);
                comboBoxItem.GetType().GetField("name", bindingFlags).SetValue(comboBoxItem, "Сеть");

                var mvfFileView = mainType.GetField("mwfFileView", bindingFlags).GetValue(d);
                ((MenuItem)mvfFileView.GetType().GetField("menuItemNew", bindingFlags).GetValue(mvfFileView)).Text = "Создать";
                ((MenuItem)mvfFileView.GetType().GetField("newFolderMenuItem", bindingFlags).GetValue(mvfFileView)).Text = "Новую папку";
                ((MenuItem)mvfFileView.GetType().GetField("menuItemView", bindingFlags).GetValue(mvfFileView)).Text = "Вид";
                ((MenuItem)mvfFileView.GetType().GetField("smallIconMenutItem", bindingFlags).GetValue(mvfFileView)).Text = "Маленькие значки";
                ((MenuItem)mvfFileView.GetType().GetField("tilesMenutItem", bindingFlags).GetValue(mvfFileView)).Text = "Плитка";
                ((MenuItem)mvfFileView.GetType().GetField("largeIconMenutItem", bindingFlags).GetValue(mvfFileView)).Text = "Большие значки";
                ((MenuItem)mvfFileView.GetType().GetField("listMenutItem", bindingFlags).GetValue(mvfFileView)).Text = "Список";
                ((MenuItem)mvfFileView.GetType().GetField("detailsMenutItem", bindingFlags).GetValue(mvfFileView)).Text = "Таблица";
                ((MenuItem)mvfFileView.GetType().GetField("showHiddenFilesMenuItem", bindingFlags).GetValue(mvfFileView)).Text = "Показать скрытые файлы";

                ContextMenu menueToolBarButtonContextMenu = (ContextMenu)mainType.GetField("menueToolBarButtonContextMenu", bindingFlags).GetValue(d);
                foreach (MenuItem mi in menueToolBarButtonContextMenu.MenuItems)
                {
                    switch (mi.Text)
                    {
                        case "Small Icon":
                            mi.Text = "Маленькие значки";
                            break;
                        case "Tiles":
                            mi.Text = "Плитка";
                            break;
                        case "Large Icon":
                            mi.Text = "Большие значки";
                            break;
                        case "List":
                            mi.Text = "Список";
                            break;
                        case "Details":
                            mi.Text = "Таблица";
                            break; 
                    }

                }

                ((ToolBarButton)mainType.GetField("backToolBarButton", bindingFlags).GetValue(d)).ToolTipText = "Переход к последней просмотренной папке";
                ((ToolBarButton)mainType.GetField("upToolBarButton", bindingFlags).GetValue(d)).ToolTipText = "На один уровень вверх";
                ((ToolBarButton)mainType.GetField("newdirToolBarButton", bindingFlags).GetValue(d)).ToolTipText = "Создание новой папки";
                ((ToolBarButton)mainType.GetField("menueToolBarButton", bindingFlags).GetValue(d)).ToolTipText = "Меню \"Вид\"";

                //Fix icons
                ((ImageList)mainType.GetField("imageListTopToolbar", bindingFlags).GetValue(d)).ColorDepth = ColorDepth.Depth16Bit;
                ((ImageList)dirComboBox.GetType().GetField("imageList", bindingFlags).GetValue(dirComboBox)).ColorDepth = ColorDepth.Depth16Bit;

            }
            catch (Exception)
            {
                //do nothing 
            }
        }

Но это не всё. Остался непереведённым диалог создания новой папки (это который вызывается через контекстное меню или по кнопке тулбара внутри файлового диалога): Новая папка

Как до него добраться - не знаю.

→ Ссылка