* 重构多语翻译类

This commit is contained in:
Sunny 2024-09-16 21:47:57 +08:00
parent 3a506824d1
commit 1ccaaad57c
17 changed files with 76 additions and 8 deletions

View File

@ -44,6 +44,9 @@ namespace Sunny.UI
SetStyleFlags(true, false); SetStyleFlags(true, false);
} }
[Browsable(false)]
public override string[] FormTranslatorProperties => ["Text"];
private void UIGroupBox_TextAlignmentChange(object sender, ContentAlignment alignment) private void UIGroupBox_TextAlignmentChange(object sender, ContentAlignment alignment)
{ {
Invalidate(); Invalidate();

View File

@ -71,6 +71,9 @@ namespace Sunny.UI
rectDisableColor = UIStyles.Blue.RectDisableColor; rectDisableColor = UIStyles.Blue.RectDisableColor;
} }
[Browsable(false)]
public override string[] FormTranslatorProperties => ["Text"];
/// <summary> /// <summary>
/// 设置控件缩放比例 /// 设置控件缩放比例
/// </summary> /// </summary>

View File

@ -34,7 +34,7 @@ namespace Sunny.UI
[ToolboxItem(true)] [ToolboxItem(true)]
[DefaultEvent("Click")] [DefaultEvent("Click")]
[DefaultProperty("Text")] [DefaultProperty("Text")]
public class UILabel : Label, IStyleInterface, IZoomScale public class UILabel : Label, IStyleInterface, IZoomScale, IFormTranslator
{ {
public UILabel() public UILabel()
{ {
@ -43,6 +43,14 @@ namespace Sunny.UI
ForeColor = UIStyles.Blue.LabelForeColor; ForeColor = UIStyles.Blue.LabelForeColor;
} }
[Browsable(false)]
[Description("控件在界面显示时需要多语翻译的属性名称数组"), Category("SunnyUI")]
public string[] FormTranslatorProperties => ["Text"];
[DefaultValue(false)]
[Description("控件是否显示多语内置资源"), Category("SunnyUI")]
public bool ShowBuiltInResources { get; set; } = false;
/// <summary> /// <summary>
/// 禁止控件跟随窗体缩放 /// 禁止控件跟随窗体缩放
/// </summary> /// </summary>
@ -160,7 +168,7 @@ namespace Sunny.UI
[ToolboxItem(true)] [ToolboxItem(true)]
[DefaultEvent("Click")] [DefaultEvent("Click")]
[DefaultProperty("Text")] [DefaultProperty("Text")]
public sealed class UILinkLabel : LinkLabel, IStyleInterface, IZoomScale public sealed class UILinkLabel : LinkLabel, IStyleInterface, IZoomScale, IFormTranslator
{ {
public UILinkLabel() public UILinkLabel()
{ {
@ -174,6 +182,14 @@ namespace Sunny.UI
base.LinkColor = linkColor = ForeColor = UIStyles.Blue.LabelForeColor; base.LinkColor = linkColor = ForeColor = UIStyles.Blue.LabelForeColor;
} }
[Browsable(false)]
[Description("控件在界面显示时需要多语翻译的属性名称数组"), Category("SunnyUI")]
public string[] FormTranslatorProperties => ["Text"];
[DefaultValue(false)]
[Description("控件是否显示多语内置资源"), Category("SunnyUI")]
public bool ShowBuiltInResources { get; set; } = false;
/// <summary> /// <summary>
/// 禁止控件跟随窗体缩放 /// 禁止控件跟随窗体缩放
/// </summary> /// </summary>

View File

@ -31,7 +31,7 @@ namespace Sunny.UI
/// LED显示屏 /// LED显示屏
/// </summary> /// </summary>
[DefaultProperty("Text")] [DefaultProperty("Text")]
public class UILedDisplay : Control public class UILedDisplay : Control, IFormTranslator
{ {
#region #region
@ -85,6 +85,14 @@ namespace Sunny.UI
Version = UIGlobal.Version; Version = UIGlobal.Version;
} }
[Browsable(false)]
[Description("控件在界面显示时需要多语翻译的属性名称数组"), Category("SunnyUI")]
public string[] FormTranslatorProperties => ["Text"];
[DefaultValue(false)]
[Description("控件是否显示多语内置资源"), Category("SunnyUI")]
public bool ShowBuiltInResources { get; set; } = false;
public string Version { get; } public string Version { get; }
/// <summary> /// <summary>

View File

@ -39,6 +39,9 @@ namespace Sunny.UI
foreColor = UIStyles.Blue.LedLabelForeColor; foreColor = UIStyles.Blue.LedLabelForeColor;
} }
[Browsable(false)]
public override string[] FormTranslatorProperties => ["Text"];
/// <summary> /// <summary>
/// 重载绘图 /// 重载绘图
/// </summary> /// </summary>

View File

@ -48,6 +48,9 @@ namespace Sunny.UI
rectColor = UIStyles.Blue.LineRectColor; rectColor = UIStyles.Blue.LineRectColor;
} }
[Browsable(false)]
public override string[] FormTranslatorProperties => ["Text"];
public enum LineDirection public enum LineDirection
{ {
/// <summary> /// <summary>

View File

@ -109,6 +109,7 @@ namespace Sunny.UI
buttons[i].MouseLeave += UIDataGridPage_MouseLeave; buttons[i].MouseLeave += UIDataGridPage_MouseLeave;
buttons[i].Click += UIDataGridPage_Click; buttons[i].Click += UIDataGridPage_Click;
buttons[i].Size = new System.Drawing.Size(32, 32); buttons[i].Size = new System.Drawing.Size(32, 32);
buttons[i].ShowBuiltInResources = true;
} }
buttonTags.TryAdd(b0, -1); buttonTags.TryAdd(b0, -1);

View File

@ -678,6 +678,7 @@ namespace Sunny.UI
uiLabel2.ForeColor = Color.FromArgb(48, 48, 48); uiLabel2.ForeColor = Color.FromArgb(48, 48, 48);
uiLabel2.Location = new Point(726, 10); uiLabel2.Location = new Point(726, 10);
uiLabel2.Name = "uiLabel2"; uiLabel2.Name = "uiLabel2";
uiLabel2.ShowBuiltInResources = true;
uiLabel2.Size = new Size(21, 14); uiLabel2.Size = new Size(21, 14);
uiLabel2.TabIndex = 2; uiLabel2.TabIndex = 2;
uiLabel2.Text = "页"; uiLabel2.Text = "页";
@ -691,6 +692,7 @@ namespace Sunny.UI
uiLabel1.ForeColor = Color.FromArgb(48, 48, 48); uiLabel1.ForeColor = Color.FromArgb(48, 48, 48);
uiLabel1.Location = new Point(650, 10); uiLabel1.Location = new Point(650, 10);
uiLabel1.Name = "uiLabel1"; uiLabel1.Name = "uiLabel1";
uiLabel1.ShowBuiltInResources = true;
uiLabel1.Size = new Size(21, 14); uiLabel1.Size = new Size(21, 14);
uiLabel1.TabIndex = 0; uiLabel1.TabIndex = 0;
uiLabel1.Text = "第"; uiLabel1.Text = "第";

View File

@ -45,6 +45,9 @@ namespace Sunny.UI
SetStyleFlags(true, false, true); SetStyleFlags(true, false, true);
} }
[Browsable(false)]
public override string[] FormTranslatorProperties => ["Text"];
/// <summary> /// <summary>
/// 字体颜色 /// 字体颜色
/// </summary> /// </summary>

View File

@ -60,6 +60,9 @@ namespace Sunny.UI
fillColor = UIStyles.Blue.CheckBoxColor; fillColor = UIStyles.Blue.CheckBoxColor;
} }
[Browsable(false)]
public override string[] FormTranslatorProperties => ["Text"];
/// <summary> /// <summary>
/// 重载绘图 /// 重载绘图
/// </summary> /// </summary>

View File

@ -33,7 +33,7 @@ namespace Sunny.UI
[ToolboxItem(true)] [ToolboxItem(true)]
[DefaultEvent("Click")] [DefaultEvent("Click")]
[DefaultProperty("Text")] [DefaultProperty("Text")]
public sealed class UISmoothLabel : Label, IStyleInterface, IZoomScale public sealed class UISmoothLabel : Label, IStyleInterface, IZoomScale, IFormTranslator
{ {
private PointF point; private PointF point;
private SizeF drawSize; private SizeF drawSize;
@ -55,6 +55,14 @@ namespace Sunny.UI
Size = new Size(300, 60); Size = new Size(300, 60);
} }
[Browsable(false)]
[Description("控件在界面显示时需要多语翻译的属性名称数组"), Category("SunnyUI")]
public string[] FormTranslatorProperties => ["Text"];
[DefaultValue(false)]
[Description("控件是否显示多语内置资源"), Category("SunnyUI")]
public bool ShowBuiltInResources { get; set; } = false;
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing) if (disposing)

View File

@ -52,6 +52,9 @@ namespace Sunny.UI
Square Square
} }
[Browsable(false)]
public override string[] FormTranslatorProperties => ["ActiveText", "InActiveText"];
public UISwitch() public UISwitch()
{ {
SetStyleFlags(); SetStyleFlags();

View File

@ -53,6 +53,9 @@ namespace Sunny.UI
Height = 35; Height = 35;
} }
[Browsable(false)]
public override string[] FormTranslatorProperties => ["Text"];
private bool autoSize; private bool autoSize;
[Browsable(true)] [Browsable(true)]

View File

@ -49,6 +49,9 @@ namespace Sunny.UI
ShowRect = false; ShowRect = false;
} }
[Browsable(false)]
public override string[] FormTranslatorProperties => ["ActiveText", "InActiveText"];
[DefaultValue(false)] [DefaultValue(false)]
[Description("是否只读"), Category("SunnyUI")] [Description("是否只读"), Category("SunnyUI")]
public bool ReadOnly { get; set; } public bool ReadOnly { get; set; }

View File

@ -35,7 +35,7 @@ namespace Sunny.UI
{ {
[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(System.ComponentModel.Design.IDesigner))] [Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(System.ComponentModel.Design.IDesigner))]
[DefaultEvent("Click"), DefaultProperty("Text")] [DefaultEvent("Click"), DefaultProperty("Text")]
public partial class UIUserControl : UserControl, IStyleInterface, IZoomScale public partial class UIUserControl : UserControl, IStyleInterface, IZoomScale, IFormTranslator
{ {
private int radius = 5; private int radius = 5;
protected Color rectColor = UIStyles.Blue.PanelRectColor; protected Color rectColor = UIStyles.Blue.PanelRectColor;
@ -54,6 +54,14 @@ namespace Sunny.UI
SetStyleFlags(true, false); SetStyleFlags(true, false);
} }
[Browsable(false)]
[Description("控件在界面显示时需要多语翻译的属性名称数组"), Category("SunnyUI")]
public virtual string[] FormTranslatorProperties { get; }
[DefaultValue(false)]
[Description("控件是否显示多语内置资源"), Category("SunnyUI")]
public bool ShowBuiltInResources { get; set; } = false;
protected override void OnClick(EventArgs e) protected override void OnClick(EventArgs e)
{ {
base.OnClick(e); base.OnClick(e);

View File

@ -149,8 +149,6 @@ namespace Sunny.UI
{ {
SetInheritedStyle(UIStyles.Style); SetInheritedStyle(UIStyles.Style);
} }
Translate();
} }
public virtual void SetInheritedStyle(UIStyle style) public virtual void SetInheritedStyle(UIStyle style)

View File

@ -90,7 +90,7 @@ namespace Sunny.UI
string key = ctrl.Name + "." + propertyName; string key = ctrl.Name + "." + propertyName;
string langStr = ini.Read(section, key, ""); string langStr = ini.Read(section, key, "");
string ctrlStr = pt.GetValue(ctrl, null).ToString(); string ctrlStr = pt.GetValue(ctrl, null)?.ToString();
if (langStr.IsNullOrEmpty()) if (langStr.IsNullOrEmpty())
{ {