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.Utils;
using SpineViewer.Utils.Localize;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -20,7 +21,7 @@ namespace SpineViewer.Spine.SpineView
/// <summary>
/// 全轨道动画最大时长
/// </summary>
[DisplayName("全轨道最大时长")]
[LocalizedDisplayName(typeof(Properties.Resources), "maximumTrackLength")]
public float AnimationTracksMaxDuration => Spine.GetTrackIndices().Select(i => Spine.GetAnimationDuration(Spine.GetAnimation(i))).Max();
/// <summary>
@@ -144,7 +145,7 @@ namespace SpineViewer.Spine.SpineView
[Browsable(false)]
public int Index { get; } = i;
[DisplayName("时长")]
[LocalizedDisplayName(typeof(Properties.Resources), "duration")]
public float Duration => spine.GetAnimationDuration(spine.GetAnimation(Index));
/// <summary>

View File

@@ -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
/// 获取所属版本
/// </summary>
[TypeConverter(typeof(SpineVersionConverter))]
[DisplayName("运行时版本")]
[LocalizedDisplayName(typeof(Properties.Resources), "runtimeVersion")]
public SpineVersion Version => Spine.Version;
/// <summary>
/// 资源所在完整目录
/// </summary>
[DisplayName("资源目录")]
[LocalizedDisplayName(typeof(Properties.Resources), "resourcesPath")]
public string AssetsDir => Spine.AssetsDir;
/// <summary>
/// skel 文件完整路径
/// </summary>
[DisplayName("skel文件路径")]
[LocalizedDisplayName(typeof(Properties.Resources), "skelPath")]
public string SkelPath => Spine.SkelPath;
/// <summary>
/// atlas 文件完整路径
/// </summary>
[DisplayName("atlas文件路径")]
[LocalizedDisplayName(typeof(Properties.Resources), "atlasPath")]
public string AtlasPath => Spine.AtlasPath;
/// <summary>
/// 名称
/// </summary>
[DisplayName("名称")]
[LocalizedDisplayName(typeof(Properties.Resources), "name")]
public string Name => Spine.Name;
/// <summary>
/// 获取所属文件版本
/// </summary>
[DisplayName("文件版本")]
[LocalizedDisplayName(typeof(Properties.Resources), "fileVersion")]
public string FileVersion => Spine.FileVersion;
}
}

View File

@@ -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("渲染")]
[LocalizedDisplayName(typeof(Properties.Resources), "render")]
public SpineRenderProperty Render { get; } = new(spine);
[DisplayName("变换")]
[LocalizedDisplayName(typeof(Properties.Resources), "transform")]
public SpineTransformProperty Transform { get; } = new(spine);
[TypeConverter(typeof(ExpandableObjectConverter))]
[DisplayName("皮肤")]
[LocalizedDisplayName(typeof(Properties.Resources), "skin")]
public SpineSkinProperty Skin { get; } = new(spine);
[TypeConverter(typeof(ExpandableObjectConverter))]
[DisplayName("插槽")]
[LocalizedDisplayName(typeof(Properties.Resources), "slot")]
public SpineSlotProperty Slot { get; } = new(spine);
[TypeConverter(typeof(ExpandableObjectConverter))]
[DisplayName("动画")]
[LocalizedDisplayName(typeof(Properties.Resources), "animation")]
public SpineAnimationProperty Animation { get; } = new(spine);
[DisplayName("调试")]
[LocalizedDisplayName(typeof(Properties.Resources), "debug")]
public SpineDebugProperty Debug { get; } = new(spine);
}
}

View File

@@ -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
{
@@ -19,13 +20,13 @@ namespace SpineViewer.Spine.SpineView
/// <summary>
/// 是否被隐藏, 被隐藏的模型将仅仅在列表显示, 不参与其他行为
/// </summary>
[DisplayName("是否隐藏")]
[LocalizedDisplayName(typeof(Properties.Resources), "isHidden")]
public bool IsHidden { get => Spine.IsHidden; set => Spine.IsHidden = value; }
/// <summary>
/// 是否使用预乘Alpha
/// </summary>
[DisplayName("预乘Alpha通道")]
[LocalizedDisplayName(typeof(Properties.Resources), "usePremultipliedAlpha")]
public bool UsePremultipliedAlpha { get => Spine.UsePma; set => Spine.UsePma = value; }
}
}

View File

@@ -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
{
@@ -20,26 +21,26 @@ namespace SpineViewer.Spine.SpineView
/// <summary>
/// 缩放比例
/// </summary>
[DisplayName("缩放比例")]
[LocalizedDisplayName(typeof(Properties.Resources), "scale")]
public float Scale { get => Spine.Scale; set => Spine.Scale = value; }
/// <summary>
/// 位置
/// </summary>
[TypeConverter(typeof(PointFConverter))]
[DisplayName("位置")]
[LocalizedDisplayName(typeof(Properties.Resources), "position")]
public PointF Position { get => Spine.Position; set => Spine.Position = value; }
/// <summary>
/// 水平翻转
/// </summary>
[DisplayName("水平翻转")]
[LocalizedDisplayName(typeof(Properties.Resources), "flipX")]
public bool FlipX { get => Spine.FlipX; set => Spine.FlipX = value; }
/// <summary>
/// 垂直翻转
/// </summary>
[DisplayName("垂直翻转")]
[LocalizedDisplayName(typeof(Properties.Resources), "flipY")]
public bool FlipY { get => Spine.FlipY; set => Spine.FlipY = value; }
}
}

View File

@@ -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");
}
}
}
}

View File

@@ -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);
}
}