feat: spineview localize

This commit is contained in:
Myssal
2025-04-28 00:08:25 +07:00
parent 58b45cde31
commit 177434e503
7 changed files with 80 additions and 75 deletions

View File

@@ -1,5 +1,6 @@
using SpineViewer.Spine; using SpineViewer.Spine;
using SpineViewer.Utils; using SpineViewer.Utils;
using SpineViewer.Utils.Localize;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@@ -20,7 +21,7 @@ namespace SpineViewer.Spine.SpineView
/// <summary> /// <summary>
/// 全轨道动画最大时长 /// 全轨道动画最大时长
/// </summary> /// </summary>
[DisplayName("全轨道最大时长")] [LocalizedDisplayName(typeof(Properties.Resources), "maximumTrackLength")]
public float AnimationTracksMaxDuration => Spine.GetTrackIndices().Select(i => Spine.GetAnimationDuration(Spine.GetAnimation(i))).Max(); public float AnimationTracksMaxDuration => Spine.GetTrackIndices().Select(i => Spine.GetAnimationDuration(Spine.GetAnimation(i))).Max();
/// <summary> /// <summary>
@@ -144,8 +145,8 @@ namespace SpineViewer.Spine.SpineView
[Browsable(false)] [Browsable(false)]
public int Index { get; } = i; public int Index { get; } = i;
[DisplayName("时长")] [LocalizedDisplayName(typeof(Properties.Resources), "duration")]
public float Duration => spine.GetAnimationDuration(spine.GetAnimation(Index)); public float Duration => spine.GetAnimationDuration(spine.GetAnimation(Index));
/// <summary> /// <summary>
/// 实现了默认的转为字符串的方式 /// 实现了默认的转为字符串的方式

View File

@@ -1,5 +1,6 @@
using SpineViewer.Spine; using SpineViewer.Spine;
using SpineViewer.Utils; using SpineViewer.Utils;
using SpineViewer.Utils.Localize;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@@ -21,37 +22,37 @@ namespace SpineViewer.Spine.SpineView
/// 获取所属版本 /// 获取所属版本
/// </summary> /// </summary>
[TypeConverter(typeof(SpineVersionConverter))] [TypeConverter(typeof(SpineVersionConverter))]
[DisplayName("运行时版本")] [LocalizedDisplayName(typeof(Properties.Resources), "runtimeVersion")]
public SpineVersion Version => Spine.Version; public SpineVersion Version => Spine.Version;
/// <summary> /// <summary>
/// 资源所在完整目录 /// 资源所在完整目录
/// </summary> /// </summary>
[DisplayName("资源目录")] [LocalizedDisplayName(typeof(Properties.Resources), "resourcesPath")]
public string AssetsDir => Spine.AssetsDir; public string AssetsDir => Spine.AssetsDir;
/// <summary> /// <summary>
/// skel 文件完整路径 /// skel 文件完整路径
/// </summary> /// </summary>
[DisplayName("skel文件路径")] [LocalizedDisplayName(typeof(Properties.Resources), "skelPath")]
public string SkelPath => Spine.SkelPath; public string SkelPath => Spine.SkelPath;
/// <summary> /// <summary>
/// atlas 文件完整路径 /// atlas 文件完整路径
/// </summary> /// </summary>
[DisplayName("atlas文件路径")] [LocalizedDisplayName(typeof(Properties.Resources), "atlasPath")]
public string AtlasPath => Spine.AtlasPath; public string AtlasPath => Spine.AtlasPath;
/// <summary> /// <summary>
/// 名称 /// 名称
/// </summary> /// </summary>
[DisplayName("名称")] [LocalizedDisplayName(typeof(Properties.Resources), "name")]
public string Name => Spine.Name; public string Name => Spine.Name;
/// <summary> /// <summary>
/// 获取所属文件版本 /// 获取所属文件版本
/// </summary> /// </summary>
[DisplayName("文件版本")] [LocalizedDisplayName(typeof(Properties.Resources), "fileVersion")]
public string FileVersion => Spine.FileVersion; public string FileVersion => Spine.FileVersion;
} }
} }

View File

@@ -6,6 +6,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using SpineViewer.Spine; using SpineViewer.Spine;
using SpineViewer.Utils.Localize;
namespace SpineViewer.Spine.SpineView namespace SpineViewer.Spine.SpineView
{ {
@@ -14,28 +15,28 @@ namespace SpineViewer.Spine.SpineView
[Browsable(false)] [Browsable(false)]
public SpineObject Spine { get; } = spine; public SpineObject Spine { get; } = spine;
[DisplayName("基本信息")] [LocalizedDisplayName(typeof(Properties.Resources), "basicInfo")]
public SpineBaseInfoProperty BaseInfo { get; } = new(spine); public SpineBaseInfoProperty BaseInfo { get; } = new(spine);
[DisplayName("渲染")] [LocalizedDisplayName(typeof(Properties.Resources), "render")]
public SpineRenderProperty Render { get; } = new(spine); public SpineRenderProperty Render { get; } = new(spine);
[DisplayName("变换")] [LocalizedDisplayName(typeof(Properties.Resources), "transform")]
public SpineTransformProperty Transform { get; } = new(spine); public SpineTransformProperty Transform { get; } = new(spine);
[TypeConverter(typeof(ExpandableObjectConverter))] [TypeConverter(typeof(ExpandableObjectConverter))]
[DisplayName("皮肤")] [LocalizedDisplayName(typeof(Properties.Resources), "skin")]
public SpineSkinProperty Skin { get; } = new(spine); public SpineSkinProperty Skin { get; } = new(spine);
[TypeConverter(typeof(ExpandableObjectConverter))] [TypeConverter(typeof(ExpandableObjectConverter))]
[DisplayName("插槽")] [LocalizedDisplayName(typeof(Properties.Resources), "slot")]
public SpineSlotProperty Slot { get; } = new(spine); public SpineSlotProperty Slot { get; } = new(spine);
[TypeConverter(typeof(ExpandableObjectConverter))] [TypeConverter(typeof(ExpandableObjectConverter))]
[DisplayName("动画")] [LocalizedDisplayName(typeof(Properties.Resources), "animation")]
public SpineAnimationProperty Animation { get; } = new(spine); public SpineAnimationProperty Animation { get; } = new(spine);
[DisplayName("调试")] [LocalizedDisplayName(typeof(Properties.Resources), "debug")]
public SpineDebugProperty Debug { get; } = new(spine); public SpineDebugProperty Debug { get; } = new(spine);
} }
} }

View File

@@ -5,6 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using SpineViewer.Spine; using SpineViewer.Spine;
using SpineViewer.Utils.Localize;
namespace SpineViewer.Spine.SpineView namespace SpineViewer.Spine.SpineView
{ {
@@ -16,16 +17,16 @@ namespace SpineViewer.Spine.SpineView
[Browsable(false)] [Browsable(false)]
public SpineObject Spine { get; } = spine; public SpineObject Spine { get; } = spine;
/// <summary> /// <summary>
/// 是否被隐藏, 被隐藏的模型将仅仅在列表显示, 不参与其他行为 /// 是否被隐藏, 被隐藏的模型将仅仅在列表显示, 不参与其他行为
/// </summary> /// </summary>
[DisplayName("是否隐藏")] [LocalizedDisplayName(typeof(Properties.Resources), "isHidden")]
public bool IsHidden { get => Spine.IsHidden; set => Spine.IsHidden = value; } public bool IsHidden { get => Spine.IsHidden; set => Spine.IsHidden = value; }
/// <summary> /// <summary>
/// 是否使用预乘Alpha /// 是否使用预乘Alpha
/// </summary> /// </summary>
[DisplayName("预乘Alpha通道")] [LocalizedDisplayName(typeof(Properties.Resources), "usePremultipliedAlpha")]
public bool UsePremultipliedAlpha { get => Spine.UsePma; set => Spine.UsePma = value; } public bool UsePremultipliedAlpha { get => Spine.UsePma; set => Spine.UsePma = value; }
} }
} }

View File

@@ -6,6 +6,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using SpineViewer.Spine; using SpineViewer.Spine;
using SpineViewer.Utils; using SpineViewer.Utils;
using SpineViewer.Utils.Localize;
namespace SpineViewer.Spine.SpineView namespace SpineViewer.Spine.SpineView
{ {
@@ -17,29 +18,29 @@ namespace SpineViewer.Spine.SpineView
[Browsable(false)] [Browsable(false)]
public SpineObject Spine { get; } = spine; public SpineObject Spine { get; } = spine;
/// <summary> /// <summary>
/// 缩放比例 /// 缩放比例
/// </summary> /// </summary>
[DisplayName("缩放比例")] [LocalizedDisplayName(typeof(Properties.Resources), "scale")]
public float Scale { get => Spine.Scale; set => Spine.Scale = value; } public float Scale { get => Spine.Scale; set => Spine.Scale = value; }
/// <summary> /// <summary>
/// 位置 /// 位置
/// </summary> /// </summary>
[TypeConverter(typeof(PointFConverter))] [TypeConverter(typeof(PointFConverter))]
[DisplayName("位置")] [LocalizedDisplayName(typeof(Properties.Resources), "position")]
public PointF Position { get => Spine.Position; set => Spine.Position = value; } public PointF Position { get => Spine.Position; set => Spine.Position = value; }
/// <summary> /// <summary>
/// 水平翻转 /// 水平翻转
/// </summary> /// </summary>
[DisplayName("水平翻转")] [LocalizedDisplayName(typeof(Properties.Resources), "flipX")]
public bool FlipX { get => Spine.FlipX; set => Spine.FlipX = value; } public bool FlipX { get => Spine.FlipX; set => Spine.FlipX = value; }
/// <summary> /// <summary>
/// 垂直翻转 /// 垂直翻转
/// </summary> /// </summary>
[DisplayName("垂直翻转")] [LocalizedDisplayName(typeof(Properties.Resources), "flipY")]
public bool FlipY { get => Spine.FlipY; set => Spine.FlipY = value; } public bool FlipY { get => Spine.FlipY; set => Spine.FlipY = value; }
} }
} }

View File

@@ -12,11 +12,10 @@ namespace SpineViewer.Utils.Localize
{ {
public static class LocalizeConfiguration public static class LocalizeConfiguration
{ {
static readonly Logger logger = LogManager.GetCurrentClassLogger();
public static void UpdateLocalizeSetting(string newCulture) public static void UpdateLocalizeSetting(string newCulture)
{ {
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings["localize"] != null) if (config.AppSettings.Settings["localize"] != null)
config.AppSettings.Settings["localize"].Value = newCulture; config.AppSettings.Settings["localize"].Value = newCulture;
else else
@@ -29,15 +28,14 @@ namespace SpineViewer.Utils.Localize
public static void SetCulture() public static void SetCulture()
{ {
string cultureName = ConfigurationManager.AppSettings["localize"]; string cultureName = ConfigurationManager.AppSettings["localize"];
logger.Info($"Culture name: {cultureName}");
if (string.IsNullOrWhiteSpace(cultureName)) if (string.IsNullOrWhiteSpace(cultureName))
{ {
Thread.CurrentThread.CurrentUICulture = new CultureInfo("zh-CN"); cultureName = "zh-CN";
Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-CN");
} }
try try
{ {
var culture = new CultureInfo(cultureName); var culture = new CultureInfo(cultureName);
Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture; Thread.CurrentThread.CurrentUICulture = culture;
@@ -47,6 +45,8 @@ namespace SpineViewer.Utils.Localize
Thread.CurrentThread.CurrentUICulture = new CultureInfo("zh-CN"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("zh-CN");
Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-CN"); Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-CN");
} }
} }
} }
} }

View File

@@ -188,7 +188,7 @@ namespace SpineViewer.Utils
if (s.Length == 4) // #RGB if (s.Length == 4) // #RGB
return ParseShortHexColor(s, includeAlpha: false); 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 格式 // 处理 R,G,B,A 和 R,G,B 格式
@@ -207,11 +207,11 @@ namespace SpineViewer.Utils
if (color.IsKnownColor || color.IsNamedColor) if (color.IsKnownColor || color.IsNamedColor)
return new SFML.Graphics.Color(color.R, color.G, color.B, color.A); 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) catch (Exception ex)
{ {
throw new FormatException("无法解析颜色,请检查格式", ex); throw new FormatException(Properties.Resources.formatExceptionParseColorError, ex);
} }
} }