using System.Globalization; using System.Resources; namespace ImageProcessing.Controls; /// /// 本地化辅助类,用于管理多语言资源 /// 与 ImageProcessing 主项目的语言设置同步 /// public static class LocalizationHelper { private static ResourceManager? _resourceManager; /// /// 资源管理器 /// private static ResourceManager ResourceManager { get { if (_resourceManager == null) { _resourceManager = new ResourceManager( "ImageProcessing.Controls.Resources.Resources", typeof(LocalizationHelper).Assembly); } return _resourceManager; } } /// /// 获取本地化字符串 /// 使用当前 UI 文化(与主项目同步) /// /// 资源键 /// 本地化字符串 public static string GetString(string key) { try { // 使用 CultureInfo.CurrentUICulture,这会自动与主项目的语言设置同步 var value = ResourceManager.GetString(key, CultureInfo.CurrentUICulture); return value ?? key; } catch { return key; } } }