From 177434e5035acc16440472887b569e2eb7a44006 Mon Sep 17 00:00:00 2001 From: Myssal <143514975+myssal@users.noreply.github.com> Date: Mon, 28 Apr 2025 00:08:25 +0700 Subject: [PATCH] feat: spineview localize --- .../Spine/SpineView/SpineAnimationProperty.cs | 7 +-- .../Spine/SpineView/SpineBaseInfoProperty.cs | 53 ++++++++++--------- .../Spine/SpineView/SpineObjectProperty.cs | 27 +++++----- .../Spine/SpineView/SpineRenderProperty.cs | 19 +++---- .../Spine/SpineView/SpineTransformProperty.cs | 33 ++++++------ .../Utils/Localize/LocalizeConfiguration.cs | 10 ++-- SpineViewer/Utils/TypeConverter.cs | 6 +-- 7 files changed, 80 insertions(+), 75 deletions(-) diff --git a/SpineViewer/Spine/SpineView/SpineAnimationProperty.cs b/SpineViewer/Spine/SpineView/SpineAnimationProperty.cs index 50dc67d..f295499 100644 --- a/SpineViewer/Spine/SpineView/SpineAnimationProperty.cs +++ b/SpineViewer/Spine/SpineView/SpineAnimationProperty.cs @@ -1,5 +1,6 @@ using SpineViewer.Spine; using SpineViewer.Utils; +using SpineViewer.Utils.Localize; using System; using System.Collections.Generic; using System.ComponentModel; @@ -20,7 +21,7 @@ namespace SpineViewer.Spine.SpineView /// /// 全轨道动画最大时长 /// - [DisplayName("全轨道最大时长")] + [LocalizedDisplayName(typeof(Properties.Resources), "maximumTrackLength")] public float AnimationTracksMaxDuration => Spine.GetTrackIndices().Select(i => Spine.GetAnimationDuration(Spine.GetAnimation(i))).Max(); /// @@ -144,8 +145,8 @@ namespace SpineViewer.Spine.SpineView [Browsable(false)] public int Index { get; } = i; - [DisplayName("时长")] - public float Duration => spine.GetAnimationDuration(spine.GetAnimation(Index)); + [LocalizedDisplayName(typeof(Properties.Resources), "duration")] + public float Duration => spine.GetAnimationDuration(spine.GetAnimation(Index)); /// /// 实现了默认的转为字符串的方式 diff --git a/SpineViewer/Spine/SpineView/SpineBaseInfoProperty.cs b/SpineViewer/Spine/SpineView/SpineBaseInfoProperty.cs index c2b6fab..565bc8b 100644 --- a/SpineViewer/Spine/SpineView/SpineBaseInfoProperty.cs +++ b/SpineViewer/Spine/SpineView/SpineBaseInfoProperty.cs @@ -1,5 +1,6 @@ using SpineViewer.Spine; using SpineViewer.Utils; +using SpineViewer.Utils.Localize; using System; using System.Collections.Generic; using System.ComponentModel; @@ -21,37 +22,37 @@ namespace SpineViewer.Spine.SpineView /// 获取所属版本 /// [TypeConverter(typeof(SpineVersionConverter))] - [DisplayName("运行时版本")] + [LocalizedDisplayName(typeof(Properties.Resources), "runtimeVersion")] public SpineVersion Version => Spine.Version; - /// - /// 资源所在完整目录 - /// - [DisplayName("资源目录")] - public string AssetsDir => Spine.AssetsDir; + /// + /// 资源所在完整目录 + /// + [LocalizedDisplayName(typeof(Properties.Resources), "resourcesPath")] + public string AssetsDir => Spine.AssetsDir; - /// - /// skel 文件完整路径 - /// - [DisplayName("skel文件路径")] - public string SkelPath => Spine.SkelPath; + /// + /// skel 文件完整路径 + /// + [LocalizedDisplayName(typeof(Properties.Resources), "skelPath")] + public string SkelPath => Spine.SkelPath; - /// - /// atlas 文件完整路径 - /// - [DisplayName("atlas文件路径")] - public string AtlasPath => Spine.AtlasPath; + /// + /// atlas 文件完整路径 + /// + [LocalizedDisplayName(typeof(Properties.Resources), "atlasPath")] + public string AtlasPath => Spine.AtlasPath; - /// - /// 名称 - /// - [DisplayName("名称")] - public string Name => Spine.Name; + /// + /// 名称 + /// + [LocalizedDisplayName(typeof(Properties.Resources), "name")] + public string Name => Spine.Name; - /// - /// 获取所属文件版本 - /// - [DisplayName("文件版本")] - public string FileVersion => Spine.FileVersion; + /// + /// 获取所属文件版本 + /// + [LocalizedDisplayName(typeof(Properties.Resources), "fileVersion")] + public string FileVersion => Spine.FileVersion; } } diff --git a/SpineViewer/Spine/SpineView/SpineObjectProperty.cs b/SpineViewer/Spine/SpineView/SpineObjectProperty.cs index f08f2db..2d5f027 100644 --- a/SpineViewer/Spine/SpineView/SpineObjectProperty.cs +++ b/SpineViewer/Spine/SpineView/SpineObjectProperty.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using SpineViewer.Spine; +using SpineViewer.Utils.Localize; namespace SpineViewer.Spine.SpineView { @@ -14,28 +15,28 @@ namespace SpineViewer.Spine.SpineView [Browsable(false)] public SpineObject Spine { get; } = spine; - [DisplayName("基本信息")] + [LocalizedDisplayName(typeof(Properties.Resources), "basicInfo")] public SpineBaseInfoProperty BaseInfo { get; } = new(spine); - [DisplayName("渲染")] - public SpineRenderProperty Render { get; } = new(spine); + [LocalizedDisplayName(typeof(Properties.Resources), "render")] + public SpineRenderProperty Render { get; } = new(spine); - [DisplayName("变换")] - public SpineTransformProperty Transform { get; } = new(spine); + [LocalizedDisplayName(typeof(Properties.Resources), "transform")] + public SpineTransformProperty Transform { get; } = new(spine); [TypeConverter(typeof(ExpandableObjectConverter))] - [DisplayName("皮肤")] - public SpineSkinProperty Skin { get; } = new(spine); + [LocalizedDisplayName(typeof(Properties.Resources), "skin")] + public SpineSkinProperty Skin { get; } = new(spine); [TypeConverter(typeof(ExpandableObjectConverter))] - [DisplayName("插槽")] - public SpineSlotProperty Slot { get; } = new(spine); + [LocalizedDisplayName(typeof(Properties.Resources), "slot")] + public SpineSlotProperty Slot { get; } = new(spine); [TypeConverter(typeof(ExpandableObjectConverter))] - [DisplayName("动画")] - public SpineAnimationProperty Animation { get; } = new(spine); + [LocalizedDisplayName(typeof(Properties.Resources), "animation")] + public SpineAnimationProperty Animation { get; } = new(spine); - [DisplayName("调试")] - public SpineDebugProperty Debug { get; } = new(spine); + [LocalizedDisplayName(typeof(Properties.Resources), "debug")] + public SpineDebugProperty Debug { get; } = new(spine); } } diff --git a/SpineViewer/Spine/SpineView/SpineRenderProperty.cs b/SpineViewer/Spine/SpineView/SpineRenderProperty.cs index 6445a74..a44f5e3 100644 --- a/SpineViewer/Spine/SpineView/SpineRenderProperty.cs +++ b/SpineViewer/Spine/SpineView/SpineRenderProperty.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using SpineViewer.Spine; +using SpineViewer.Utils.Localize; namespace SpineViewer.Spine.SpineView { @@ -16,16 +17,16 @@ namespace SpineViewer.Spine.SpineView [Browsable(false)] public SpineObject Spine { get; } = spine; - /// - /// 是否被隐藏, 被隐藏的模型将仅仅在列表显示, 不参与其他行为 - /// - [DisplayName("是否隐藏")] + /// + /// 是否被隐藏, 被隐藏的模型将仅仅在列表显示, 不参与其他行为 + /// + [LocalizedDisplayName(typeof(Properties.Resources), "isHidden")] public bool IsHidden { get => Spine.IsHidden; set => Spine.IsHidden = value; } - /// - /// 是否使用预乘Alpha - /// - [DisplayName("预乘Alpha通道")] - public bool UsePremultipliedAlpha { get => Spine.UsePma; set => Spine.UsePma = value; } + /// + /// 是否使用预乘Alpha + /// + [LocalizedDisplayName(typeof(Properties.Resources), "usePremultipliedAlpha")] + public bool UsePremultipliedAlpha { get => Spine.UsePma; set => Spine.UsePma = value; } } } diff --git a/SpineViewer/Spine/SpineView/SpineTransformProperty.cs b/SpineViewer/Spine/SpineView/SpineTransformProperty.cs index cba2d1c..0905be3 100644 --- a/SpineViewer/Spine/SpineView/SpineTransformProperty.cs +++ b/SpineViewer/Spine/SpineView/SpineTransformProperty.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading.Tasks; using SpineViewer.Spine; using SpineViewer.Utils; +using SpineViewer.Utils.Localize; namespace SpineViewer.Spine.SpineView { @@ -17,29 +18,29 @@ namespace SpineViewer.Spine.SpineView [Browsable(false)] public SpineObject Spine { get; } = spine; - /// - /// 缩放比例 - /// - [DisplayName("缩放比例")] + /// + /// 缩放比例 + /// + [LocalizedDisplayName(typeof(Properties.Resources), "scale")] public float Scale { get => Spine.Scale; set => Spine.Scale = value; } /// /// 位置 /// [TypeConverter(typeof(PointFConverter))] - [DisplayName("位置")] - public PointF Position { get => Spine.Position; set => Spine.Position = value; } + [LocalizedDisplayName(typeof(Properties.Resources), "position")] + public PointF Position { get => Spine.Position; set => Spine.Position = value; } - /// - /// 水平翻转 - /// - [DisplayName("水平翻转")] - public bool FlipX { get => Spine.FlipX; set => Spine.FlipX = value; } + /// + /// 水平翻转 + /// + [LocalizedDisplayName(typeof(Properties.Resources), "flipX")] + public bool FlipX { get => Spine.FlipX; set => Spine.FlipX = value; } - /// - /// 垂直翻转 - /// - [DisplayName("垂直翻转")] - public bool FlipY { get => Spine.FlipY; set => Spine.FlipY = value; } + /// + /// 垂直翻转 + /// + [LocalizedDisplayName(typeof(Properties.Resources), "flipY")] + public bool FlipY { get => Spine.FlipY; set => Spine.FlipY = value; } } } diff --git a/SpineViewer/Utils/Localize/LocalizeConfiguration.cs b/SpineViewer/Utils/Localize/LocalizeConfiguration.cs index ed636d6..dc6e533 100644 --- a/SpineViewer/Utils/Localize/LocalizeConfiguration.cs +++ b/SpineViewer/Utils/Localize/LocalizeConfiguration.cs @@ -12,11 +12,10 @@ namespace SpineViewer.Utils.Localize { public static class LocalizeConfiguration { - static readonly Logger logger = LogManager.GetCurrentClassLogger(); - public static void UpdateLocalizeSetting(string newCulture) { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); + if (config.AppSettings.Settings["localize"] != null) config.AppSettings.Settings["localize"].Value = newCulture; else @@ -29,15 +28,14 @@ namespace SpineViewer.Utils.Localize public static void SetCulture() { string cultureName = ConfigurationManager.AppSettings["localize"]; - logger.Info($"Culture name: {cultureName}"); if (string.IsNullOrWhiteSpace(cultureName)) { - Thread.CurrentThread.CurrentUICulture = new CultureInfo("zh-CN"); - Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-CN"); + cultureName = "zh-CN"; } try { + var culture = new CultureInfo(cultureName); Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; @@ -47,6 +45,8 @@ namespace SpineViewer.Utils.Localize Thread.CurrentThread.CurrentUICulture = new CultureInfo("zh-CN"); Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-CN"); } + + } } } diff --git a/SpineViewer/Utils/TypeConverter.cs b/SpineViewer/Utils/TypeConverter.cs index 81cc71c..ffb85b7 100644 --- a/SpineViewer/Utils/TypeConverter.cs +++ b/SpineViewer/Utils/TypeConverter.cs @@ -188,7 +188,7 @@ namespace SpineViewer.Utils if (s.Length == 4) // #RGB return ParseShortHexColor(s, includeAlpha: false); - throw new FormatException("无法解析颜色,请使用 #RRGGBBAA、#RRGGBB、#RGBA 或 #RGB 格式"); + throw new FormatException(Properties.Resources.formatExceptionParseColor); } // 处理 R,G,B,A 和 R,G,B 格式 @@ -207,11 +207,11 @@ namespace SpineViewer.Utils if (color.IsKnownColor || color.IsNamedColor) return new SFML.Graphics.Color(color.R, color.G, color.B, color.A); - throw new FormatException("无法解析颜色,请使用已知的颜色名称"); + throw new FormatException(Properties.Resources.formatExceptionUnknownColor); } catch (Exception ex) { - throw new FormatException("无法解析颜色,请检查格式", ex); + throw new FormatException(Properties.Resources.formatExceptionParseColorError, ex); } }