From 842af5ce35fd8f4fc2fe305f68d47b0d99c8bc6c Mon Sep 17 00:00:00 2001 From: KawaiiZapic Date: Wed, 25 Sep 2024 14:41:06 +0800 Subject: [PATCH] feat: localization --- PTSteamLauncher.sln | 2 +- .../Resource.Designer.cs} | 63 ++++++-- .../Resource.resx} | 23 ++- .../Localizations/Resource.zh-CN.resx | 144 ++++++++++++++++++ PTSteamLauncher/Main.cs | 52 ++++--- PTSteamLauncher/PTSteamLauncher.csproj | 24 ++- PTSteamLauncher/plugin.json | 2 +- 7 files changed, 264 insertions(+), 46 deletions(-) rename PTSteamLauncher/{Properties/Resources.Designer.cs => Localizations/Resource.Designer.cs} (60%) rename PTSteamLauncher/{Properties/Resources.resx => Localizations/Resource.resx} (89%) create mode 100644 PTSteamLauncher/Localizations/Resource.zh-CN.resx diff --git a/PTSteamLauncher.sln b/PTSteamLauncher.sln index 199b2a3..f7e3fa4 100644 --- a/PTSteamLauncher.sln +++ b/PTSteamLauncher.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.10.35201.131 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PTSteamLauncher", "PTSteamLauncher\PTSteamLauncher.csproj", "{7C774FAC-91F6-436B-B398-DDF5E21F2EDD}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PTSteamLauncher", "PTSteamLauncher\PTSteamLauncher.csproj", "{7C774FAC-91F6-436B-B398-DDF5E21F2EDD}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/PTSteamLauncher/Properties/Resources.Designer.cs b/PTSteamLauncher/Localizations/Resource.Designer.cs similarity index 60% rename from PTSteamLauncher/Properties/Resources.Designer.cs rename to PTSteamLauncher/Localizations/Resource.Designer.cs index cf35977..df28c1f 100644 --- a/PTSteamLauncher/Properties/Resources.Designer.cs +++ b/PTSteamLauncher/Localizations/Resource.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace Community.PowerToys.Run.Plugin.SteamLauncher.Properties { +namespace Community.PowerToys.Run.Plugin.SteamLauncher.Localizations { using System; @@ -22,14 +22,14 @@ namespace Community.PowerToys.Run.Plugin.SteamLauncher.Properties { [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { + internal class Resource { private static global::System.Resources.ResourceManager resourceMan; private static global::System.Globalization.CultureInfo resourceCulture; [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { + internal Resource() { } /// @@ -39,7 +39,7 @@ internal Resources() { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Community.PowerToys.Run.Plugin.SteamLauncher.Properties.Resources", typeof(Resources).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Community.PowerToys.Run.Plugin.SteamLauncher.Localizations.Resource", typeof(Resource).Assembly); resourceMan = temp; } return resourceMan; @@ -61,7 +61,43 @@ internal Resources() { } /// - /// 查找类似 SteamLauncher plugin 的本地化字符串。 + /// 查找类似 Open Game Config 的本地化字符串。 + /// + internal static string action_options { + get { + return ResourceManager.GetString("action_options", resourceCulture); + } + } + + /// + /// 查找类似 Play 的本地化字符串。 + /// + internal static string action_play { + get { + return ResourceManager.GetString("action_play", resourceCulture); + } + } + + /// + /// 查找类似 Steam Game 的本地化字符串。 + /// + internal static string game_description { + get { + return ResourceManager.GetString("game_description", resourceCulture); + } + } + + /// + /// 查找类似 Steam Launcher can't be initialized 的本地化字符串。 + /// + internal static string initialization_failed_title { + get { + return ResourceManager.GetString("initialization_failed_title", resourceCulture); + } + } + + /// + /// 查找类似 Launch your steam games. 的本地化字符串。 /// internal static string plugin_description { get { @@ -70,7 +106,7 @@ internal static string plugin_description { } /// - /// 查找类似 SteamLauncher 的本地化字符串。 + /// 查找类似 Steam Launcher 的本地化字符串。 /// internal static string plugin_name { get { @@ -79,11 +115,20 @@ internal static string plugin_name { } /// - /// 查找类似 SteamLauncher settings 的本地化字符串。 + /// 查找类似 Try re-install Steam by official installer. 的本地化字符串。 + /// + internal static string steam_not_found_description { + get { + return ResourceManager.GetString("steam_not_found_description", resourceCulture); + } + } + + /// + /// 查找类似 Can't find Steam 的本地化字符串。 /// - internal static string plugin_setting { + internal static string steam_not_found_title { get { - return ResourceManager.GetString("plugin_setting", resourceCulture); + return ResourceManager.GetString("steam_not_found_title", resourceCulture); } } } diff --git a/PTSteamLauncher/Properties/Resources.resx b/PTSteamLauncher/Localizations/Resource.resx similarity index 89% rename from PTSteamLauncher/Properties/Resources.resx rename to PTSteamLauncher/Localizations/Resource.resx index 879d539..cc7278e 100644 --- a/PTSteamLauncher/Properties/Resources.resx +++ b/PTSteamLauncher/Localizations/Resource.resx @@ -117,13 +117,28 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Open Game Config + + + Play + + + Steam Game + + + Steam Launcher can't be initialized + - SteamLauncher plugin + Launch your steam games. - SteamLauncher + Steam Launcher + + + Can't find Steam - - SteamLauncher settings + + Try re-install Steam by official installer. \ No newline at end of file diff --git a/PTSteamLauncher/Localizations/Resource.zh-CN.resx b/PTSteamLauncher/Localizations/Resource.zh-CN.resx new file mode 100644 index 0000000..b9565e1 --- /dev/null +++ b/PTSteamLauncher/Localizations/Resource.zh-CN.resx @@ -0,0 +1,144 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 打开游戏设置 + + + 启动 + + + Steam 游戏 + + + Steam Launcher 无法初始化 + + + 启动安装的 Steam 游戏 + + + Steam Launcher + + + 找不到 Steam + + + 尝试用官方安装包重新安装Steam + + \ No newline at end of file diff --git a/PTSteamLauncher/Main.cs b/PTSteamLauncher/Main.cs index 946aa1f..f0d0d0a 100644 --- a/PTSteamLauncher/Main.cs +++ b/PTSteamLauncher/Main.cs @@ -4,20 +4,18 @@ using System.Text.RegularExpressions; using Wox.Infrastructure; using Wox.Plugin; +using Community.PowerToys.Run.Plugin.SteamLauncher.Localizations; namespace Community.PowerToys.Run.Plugin.SteamLauncher { public partial class Main: IPlugin, IReloadable, IContextMenu, IDisposable { [GeneratedRegex("\"path\"\\s*\"([^\"]*)\"")] private static partial Regex LibraryPathMather(); - public string Name => "Steam Launcher"; + public string Name => Resource.plugin_name; + public string Description => Resource.plugin_description; public static string PluginID => "9e13e2aa-da92-4094-84f8-6f2e2d3e90db"; - public string Description => "Launch your steam games."; - - private bool _Initialized = false; - - private string _InitialzedFailedReason = ""; + private Exception? _InitialzedFailedReason; private string SteamPath = ""; @@ -31,30 +29,35 @@ public partial class Main: IPlugin, IReloadable, IContextMenu, IDisposable { private bool _disposed; public void Init(PluginInitContext context) { - try { - InitSteamData(); - _Initialized = true; - } catch (Exception e) { - _InitialzedFailedReason = e.Message; - _Initialized = false; - } + ReloadData(); } public List Query(Query query) { - if (!_Initialized) { + if (_InitialzedFailedReason != null) { + if (_InitialzedFailedReason is SteamNotFoundException) { + return [ + new Result { + Title = Resource.steam_not_found_title, + SubTitle = Resource.steam_not_found_description + } + ]; + } return [ new Result { - Title = "Steam Launcher can't be initialized", - SubTitle = _InitialzedFailedReason + Title = Resource.initialization_failed_title, + SubTitle = _InitialzedFailedReason.Message, + Action = (e) => { + throw _InitialzedFailedReason; + } } - ]; + ]; } List results = []; foreach (SteamGame game in steamGames) { if (StringMatcher.FuzzySearch(query.Search, game.name).Success || (game.localizationName != null && StringMatcher.FuzzySearch(query.Search, game.localizationName).Success)) { results.Add(new Result { Title = game.localizationName ?? game.name, - SubTitle = "Steam Game", + SubTitle = (game.localizationName != null && game.localizationName.Trim() != game.name.Trim()) ? game.name : Resource.game_description, IcoPath = game.icon, ContextData = game.id, Action = (e) => { @@ -70,10 +73,9 @@ public List Query(Query query) { public void ReloadData() { try { InitSteamData(); - _Initialized = true; + _InitialzedFailedReason = null; } catch (Exception e) { - _InitialzedFailedReason = e.Message; - _Initialized = false; + _InitialzedFailedReason = e; } } @@ -92,7 +94,7 @@ private void InitSteamData() { SteamPath = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Valve\\Steam", "InstallPath", null)?.ToString() ?? Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Valve\\Steam", "InstallPath", null)?.ToString() - ?? throw new Exception("Can't detected Steam installation path."); + ?? throw new SteamNotFoundException(); var libWatcher = new FileSystemWatcher(Path.Combine(SteamPath, "config")) { Filter = "libraryfolders.vdf", @@ -136,7 +138,7 @@ public List LoadContextMenus(Result selectedResult) { new ContextMenuResult { Glyph = "\xE768", FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets", - Title = "Play", + Title = Resource.action_play, Action = (e) => { Process.Start(Path.Combine(SteamPath, "steam.exe"), "steam://launch/" + id); return true; @@ -145,7 +147,7 @@ public List LoadContextMenus(Result selectedResult) { new ContextMenuResult { Glyph = "\xE713", FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets", - Title = "Open Game Config", + Title = Resource.action_options, Action = (e) => { Process.Start(Path.Combine(SteamPath, "steam.exe"), "steam://gameproperties/" + id); return true; @@ -225,4 +227,6 @@ public SteamGame[] GetGames() { return [.. FoundGames]; } } + + class SteamNotFoundException : Exception { } } diff --git a/PTSteamLauncher/PTSteamLauncher.csproj b/PTSteamLauncher/PTSteamLauncher.csproj index c0f8031..c006077 100644 --- a/PTSteamLauncher/PTSteamLauncher.csproj +++ b/PTSteamLauncher/PTSteamLauncher.csproj @@ -12,6 +12,7 @@ $(Title) KawaiiZapic + true @@ -51,14 +52,23 @@ - - ResXFileCodeGenerator - Resources.Designer.cs + + ResXFileCodeGenerator + Resource.Designer.cs - - True - True - Resources.resx + + ResXFileCodeGenerator + Resource.zh-CN.Designer.cs + + + True + True + Resource.resx + + + True + True + Resource.zh-CN.resx diff --git a/PTSteamLauncher/plugin.json b/PTSteamLauncher/plugin.json index a103166..765e6b9 100644 --- a/PTSteamLauncher/plugin.json +++ b/PTSteamLauncher/plugin.json @@ -4,7 +4,7 @@ "Disabled": false, "IsGlobal": false, "Name": "Steam Launcher", - "Version": "0.2.1", + "Version": "0.2.2", "Author": "Zapic", "Language": "csharp", "Website": "https://github.com/KawaiiZapic/PowerToysSteamLauncher",