* 重构多语翻译类

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);
}
[Browsable(false)]
public override string[] FormTranslatorProperties => ["Text"];
private void UIGroupBox_TextAlignmentChange(object sender, ContentAlignment alignment)
{
Invalidate();

View File

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

View File

@ -34,7 +34,7 @@ namespace Sunny.UI
[ToolboxItem(true)]
[DefaultEvent("Click")]
[DefaultProperty("Text")]
public class UILabel : Label, IStyleInterface, IZoomScale
public class UILabel : Label, IStyleInterface, IZoomScale, IFormTranslator
{
public UILabel()
{
@ -43,6 +43,14 @@ namespace Sunny.UI
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>
@ -160,7 +168,7 @@ namespace Sunny.UI
[ToolboxItem(true)]
[DefaultEvent("Click")]
[DefaultProperty("Text")]
public sealed class UILinkLabel : LinkLabel, IStyleInterface, IZoomScale
public sealed class UILinkLabel : LinkLabel, IStyleInterface, IZoomScale, IFormTranslator
{
public UILinkLabel()
{
@ -174,6 +182,14 @@ namespace Sunny.UI
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>

View File

@ -31,7 +31,7 @@ namespace Sunny.UI
/// LED显示屏
/// </summary>
[DefaultProperty("Text")]
public class UILedDisplay : Control
public class UILedDisplay : Control, IFormTranslator
{
#region
@ -85,6 +85,14 @@ namespace Sunny.UI
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; }
/// <summary>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -33,7 +33,7 @@ namespace Sunny.UI
[ToolboxItem(true)]
[DefaultEvent("Click")]
[DefaultProperty("Text")]
public sealed class UISmoothLabel : Label, IStyleInterface, IZoomScale
public sealed class UISmoothLabel : Label, IStyleInterface, IZoomScale, IFormTranslator
{
private PointF point;
private SizeF drawSize;
@ -55,6 +55,14 @@ namespace Sunny.UI
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)
{
if (disposing)

View File

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

View File

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

View File

@ -49,6 +49,9 @@ namespace Sunny.UI
ShowRect = false;
}
[Browsable(false)]
public override string[] FormTranslatorProperties => ["ActiveText", "InActiveText"];
[DefaultValue(false)]
[Description("是否只读"), Category("SunnyUI")]
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))]
[DefaultEvent("Click"), DefaultProperty("Text")]
public partial class UIUserControl : UserControl, IStyleInterface, IZoomScale
public partial class UIUserControl : UserControl, IStyleInterface, IZoomScale, IFormTranslator
{
private int radius = 5;
protected Color rectColor = UIStyles.Blue.PanelRectColor;
@ -54,6 +54,14 @@ namespace Sunny.UI
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)
{
base.OnClick(e);

View File

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

View File

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