* 重构多语翻译类
This commit is contained in:
parent
7af419a5c0
commit
e67f03d9da
@ -54,77 +54,50 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
public static class TranslateHelper
|
public static class TranslateHelper
|
||||||
{
|
{
|
||||||
private static List<string> Ignores =
|
private static List<string> Includes = [
|
||||||
[
|
//SunnyUI Controls
|
||||||
"UIContextMenuStrip",
|
"UIButton",
|
||||||
"UIStyleManager",
|
"UISymbolButton",
|
||||||
"UILogo",
|
"UIGroupBox",
|
||||||
"UIPagination",
|
"UICheckBox",
|
||||||
"UIMiniPagination",
|
|
||||||
"UIAnalogMeter",
|
|
||||||
"UIBattery",
|
|
||||||
"UICalendar",
|
|
||||||
"UIColorPicker",
|
|
||||||
"UIComboBox",
|
|
||||||
"UIComboDataGridView",
|
|
||||||
"UIComboTreeView",
|
|
||||||
"UIDataGridViewFooter",
|
|
||||||
"UIDatePicker",
|
"UIDatePicker",
|
||||||
"UIDateTimePicker",
|
"UIDateTimePicker",
|
||||||
"UIDigitalLabel",
|
"UIHeaderButton",
|
||||||
"UIDoubleUpDown",
|
"UIImageButton",
|
||||||
"UIEdit",
|
"UILabel",
|
||||||
"UIFlowLayoutPanel",
|
"UILinkLabel",
|
||||||
"UIGifAvatar",
|
"UICheckBoxGroup",
|
||||||
"UIHorScrollBar",
|
"UIRadioButtonGroup",
|
||||||
"UIHorScrollBarEx",
|
"UILine",
|
||||||
"UIImageListBox",
|
"UIPanel",
|
||||||
"UIIntegerUpDown",
|
"UIRadioButton",
|
||||||
"UIIPTextBox",
|
"UIScrollingText",
|
||||||
"UILedBulb",
|
"UISmoothLabel",
|
||||||
"UILedStopwatch",
|
"UISwitch",
|
||||||
"UILight",
|
"UISymbolLabel",
|
||||||
"UIListBox",
|
|
||||||
"UIListBoxEx",
|
|
||||||
"UIMillisecondTimer",
|
|
||||||
"UINavMenu",
|
|
||||||
"UINumPadTextBox",
|
|
||||||
"UIPipe",
|
|
||||||
"UIProgressIndicator",
|
|
||||||
"UIProcessBar",
|
|
||||||
"UIRichTextBox",
|
|
||||||
"UIRoundMeter",
|
|
||||||
"UIRoundProcess",
|
|
||||||
"UIRuler",
|
|
||||||
"UIScrollBar",
|
|
||||||
"UISignal",
|
|
||||||
"UISplitContainer",
|
|
||||||
"UITabControl",
|
|
||||||
"UITabControlMenu",
|
|
||||||
"UITableLayoutPanel",
|
|
||||||
"UITextBox",
|
|
||||||
"UIThermometer",
|
|
||||||
"UITimePicker",
|
"UITimePicker",
|
||||||
"UIToolTip",
|
"UITurnSwitch",
|
||||||
"UITrackBar",
|
"UITitlePanel"//,
|
||||||
"UITransfer",
|
//Native Controls
|
||||||
"UITransparentPanel",
|
//"Button",
|
||||||
"UITreeView",
|
//"ToolStripMenuItem",
|
||||||
"UIValve",
|
//"CheckBox",
|
||||||
"UIVerificationCode",
|
//"RadioButton",
|
||||||
"UIVerScrollBarEx",
|
//"GroupBox",
|
||||||
"UIWaitingBar",
|
//"Label",
|
||||||
"UIBarChart",
|
//"LinkLabel"
|
||||||
"UIChart",
|
|
||||||
"UIDoughnutChart",
|
|
||||||
"UILineChart",
|
|
||||||
"UIPieChart"
|
|
||||||
];
|
];
|
||||||
|
|
||||||
private static List<string> Includes =
|
private static Dictionary<string, string> NativeControlsProperty = new Dictionary<string, string>()
|
||||||
[
|
{
|
||||||
"System.Windows.Forms.ToolStripMenuItem"
|
["Button"] = "Text",
|
||||||
];
|
["ToolStripMenuItem"] = "Text",
|
||||||
|
["CheckBox"] = "Text",
|
||||||
|
["RadioButton"] = "Text",
|
||||||
|
["GroupBox"] = "Text",
|
||||||
|
["Label"] = "Text",
|
||||||
|
["LinkLabel"] = "Text"
|
||||||
|
};
|
||||||
|
|
||||||
public static void LoadCsproj(string csprojFile)
|
public static void LoadCsproj(string csprojFile)
|
||||||
{
|
{
|
||||||
@ -164,57 +137,42 @@ namespace Sunny.UI
|
|||||||
ctrladds.Clear();
|
ctrladds.Clear();
|
||||||
bool isStart = false;
|
bool isStart = false;
|
||||||
string inifile = "";
|
string inifile = "";
|
||||||
|
string strnamespace = "";
|
||||||
foreach (var line in lines)
|
foreach (var line in lines)
|
||||||
{
|
{
|
||||||
if (line.Trim().StartsWith("namespace"))
|
if (line.Trim().StartsWith("namespace"))
|
||||||
{
|
{
|
||||||
inifile = line.Trim().Replace("namespace", "").Trim() + ".";
|
strnamespace = inifile = line.Trim().Replace("namespace", "").Trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.Trim().Contains("partial class"))
|
if (line.Trim().Contains("partial class"))
|
||||||
{
|
{
|
||||||
inifile += line.Trim().Replace("partial class", "").Trim();
|
inifile += "." + line.Trim().Replace("partial class", "").Trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.Contains("private void InitializeComponent()")) isStart = true;
|
if (line.Contains("private void InitializeComponent()")) isStart = true;
|
||||||
|
|
||||||
if (isStart)
|
if (!isStart) continue;
|
||||||
|
|
||||||
|
if (line.Contains(".Controls.Add"))
|
||||||
{
|
{
|
||||||
if (line.Contains(".Controls.Add"))
|
ctrladds.Add(line.Between("(", ")"),
|
||||||
ctrladds.Add(
|
line.SplitBeforeLast(".Controls.Add").Replace("this.", "").Trim());
|
||||||
line.Between("(", ")"),
|
|
||||||
line.SplitBeforeLast(".Controls.Add").Replace("this.", "").Trim());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isStart && line.Trim().StartsWith("private") && line.Trim().EndsWith(";"))
|
if (line.Trim().StartsWith("private") && line.Trim().EndsWith(";"))
|
||||||
{
|
{
|
||||||
string[] items = line.Trim().Split(" ");
|
string[] items = line.Trim().Split(" ");
|
||||||
string name = items[2].Replace(";", "");
|
string name = items[2].Replace(";", "");
|
||||||
string classname = items[1];
|
string classname = items[1];
|
||||||
|
|
||||||
if (Ignores.Contains(classname)) continue;
|
if (!Includes.Contains(classname.SplitLast("."))) continue;
|
||||||
|
|
||||||
if (classname.SplitLast(".").StartsWith("UI") || Includes.Contains(classname))
|
ctrladds.TryGetValue("this." + name, out string parent);
|
||||||
{
|
if (parent.IsValid())
|
||||||
ctrladds.TryGetValue("this." + name, out string parent);
|
names.Add($"{parent},{classname},{name}");
|
||||||
if (parent.IsValid())
|
else
|
||||||
names.Add($"{parent},{classname},{name}");
|
names.Add($"{classname},{name}");
|
||||||
else
|
|
||||||
names.Add($"{classname},{name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var line in lines)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < names.Count; i++)
|
|
||||||
{
|
|
||||||
if (names[i].SplitSeparatorCount(",") >= 1) continue;
|
|
||||||
string add = $".Controls.Add(this.{names[i]});";
|
|
||||||
if (line.Contains(add))
|
|
||||||
{
|
|
||||||
names[i] = line.Replace(add, "").Replace("this.", "").Trim() + "," + names[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,6 +267,32 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FieldInfo[] fieldInfo = form.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
|
foreach (var info in fieldInfo)
|
||||||
|
{
|
||||||
|
if (info.FieldType.Name == "UIContextMenuStrip" || info.FieldType.Name == "ContextMenuStrip")
|
||||||
|
{
|
||||||
|
ContextMenuStrip context = (ContextMenuStrip)info.GetValue(form);
|
||||||
|
foreach (var item in context.Items)
|
||||||
|
{
|
||||||
|
if (item is ToolStripMenuItem tsmi && Ctrls2.Keys.Contains(tsmi.Name))
|
||||||
|
{
|
||||||
|
key = tsmi.Name + ".Text";
|
||||||
|
string langStr = ini.Read(section, key, "");
|
||||||
|
string ctrlStr = tsmi.Text;
|
||||||
|
if (langStr.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
if (ctrlStr.IsValid()) ini.Write(section, key, ctrlStr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tsmi.Text = langStr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ini.UpdateFile();
|
ini.UpdateFile();
|
||||||
ini.Dispose();
|
ini.Dispose();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user