From ed78e915539b5d5f5c6fa17d4b128f66fe35cc7c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Mar 2026 15:22:06 +0000 Subject: [PATCH 1/2] Initial plan From 0fd4a45af06d1e0dca7720abd67708866fc34f94 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Mar 2026 15:29:57 +0000 Subject: [PATCH 2/2] Add multi-language support (zh-CN, en, ja) to RevitGenTest Co-authored-by: ShrlAlgo <40654941+ShrlAlgo@users.noreply.github.com> Agent-Logs-Url: https://github.com/ShrlAlgo/RevitGen/sessions/312799f0-4efa-4380-8607-b68f27ac5497 --- RevitGenTest/LanguageManager.cs | 103 ++++++++++++++++++ RevitGenTest/Properties/Resources.Designer.cs | 27 +++++ RevitGenTest/Properties/Resources.en.resx | 70 ++++++++++++ RevitGenTest/Properties/Resources.ja.resx | 70 ++++++++++++ RevitGenTest/Properties/Resources.resx | 9 ++ RevitGenTest/RevitAddin.cs | 8 +- RevitGenTest/RevitGenTest.csproj | 8 ++ 7 files changed, 291 insertions(+), 4 deletions(-) create mode 100644 RevitGenTest/LanguageManager.cs create mode 100644 RevitGenTest/Properties/Resources.en.resx create mode 100644 RevitGenTest/Properties/Resources.ja.resx diff --git a/RevitGenTest/LanguageManager.cs b/RevitGenTest/LanguageManager.cs new file mode 100644 index 0000000..0142112 --- /dev/null +++ b/RevitGenTest/LanguageManager.cs @@ -0,0 +1,103 @@ +using System; +using System.Globalization; +using System.IO; +using System.Threading; + +namespace RevitGenTest +{ + /// + /// Manages language/locale preferences for the addin. + /// Supports zh-CN (Chinese), en (English), and ja (Japanese). + /// + public static class LanguageManager + { + private static readonly string SettingsDirectory = Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), + "RevitGenTest"); + + private static readonly string SettingsFilePath = Path.Combine( + SettingsDirectory, + "language.txt"); + + /// + /// The language codes supported by this addin. + /// + public static readonly string[] SupportedLanguages = { "zh-CN", "en", "ja" }; + + /// + /// Gets the current UI language code. + /// + public static string CurrentLanguage => Thread.CurrentThread.CurrentUICulture.Name; + + /// + /// Loads the saved language preference and applies it to the current thread. + /// Falls back to the default culture if no preference is saved or if it cannot be loaded. + /// + public static void LoadLanguagePreference() + { + try + { + if (File.Exists(SettingsFilePath)) + { + var language = File.ReadAllText(SettingsFilePath).Trim(); + ApplyLanguage(language); + } + } + catch (IOException) + { + // Fall back to system default if loading fails + } + catch (UnauthorizedAccessException) + { + // Fall back to system default if access is denied + } + } + + /// + /// Saves the language preference to disk so it persists across sessions. + /// + /// The BCP 47 language code to save (e.g. "zh-CN", "en", "ja"). + public static void SaveLanguagePreference(string languageCode) + { + try + { + if (!Directory.Exists(SettingsDirectory)) + Directory.CreateDirectory(SettingsDirectory); + + File.WriteAllText(SettingsFilePath, languageCode); + } + catch (IOException) + { + // Ignore save failures silently + } + catch (UnauthorizedAccessException) + { + // Ignore save failures silently + } + } + + /// + /// Switches the UI language to the specified culture code and saves the preference. + /// + /// The BCP 47 language code to apply (e.g. "zh-CN", "en", "ja"). + public static void SwitchLanguage(string languageCode) + { + ApplyLanguage(languageCode); + SaveLanguagePreference(languageCode); + } + + private static void ApplyLanguage(string languageCode) + { + try + { + var culture = new CultureInfo(languageCode); + Thread.CurrentThread.CurrentUICulture = culture; + Properties.Resources.Culture = culture; + } + catch (CultureNotFoundException) + { + // Fall back to default culture if the specified code is not recognized + } + } + } +} diff --git a/RevitGenTest/Properties/Resources.Designer.cs b/RevitGenTest/Properties/Resources.Designer.cs index 432a9e4..653f001 100644 --- a/RevitGenTest/Properties/Resources.Designer.cs +++ b/RevitGenTest/Properties/Resources.Designer.cs @@ -79,5 +79,32 @@ internal static System.Drawing.Bitmap CodeList_32px { return ((System.Drawing.Bitmap)(obj)); } } + + /// + /// 查找类似 项目中没有找到任何墙。 的本地化字符串。 + /// + internal static string NoWallsFound { + get { + return ResourceManager.GetString("NoWallsFound", resourceCulture); + } + } + + /// + /// 查找类似 成功 的本地化字符串。 + /// + internal static string SuccessTitle { + get { + return ResourceManager.GetString("SuccessTitle", resourceCulture); + } + } + + /// + /// 查找类似 找到了 {0} 面墙。 的本地化字符串。 + /// + internal static string FoundWallsMessage { + get { + return ResourceManager.GetString("FoundWallsMessage", resourceCulture); + } + } } } diff --git a/RevitGenTest/Properties/Resources.en.resx b/RevitGenTest/Properties/Resources.en.resx new file mode 100644 index 0000000..d2cad9f --- /dev/null +++ b/RevitGenTest/Properties/Resources.en.resx @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + No walls found in the project. + + + Success + + + Found {0} wall(s). + + diff --git a/RevitGenTest/Properties/Resources.ja.resx b/RevitGenTest/Properties/Resources.ja.resx new file mode 100644 index 0000000..16ddbe5 --- /dev/null +++ b/RevitGenTest/Properties/Resources.ja.resx @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + プロジェクトに壁が見つかりませんでした。 + + + 成功 + + + {0} 個の壁が見つかりました。 + + diff --git a/RevitGenTest/Properties/Resources.resx b/RevitGenTest/Properties/Resources.resx index 918b2ce..23c421e 100644 --- a/RevitGenTest/Properties/Resources.resx +++ b/RevitGenTest/Properties/Resources.resx @@ -124,4 +124,13 @@ ..\Resources\CodeList_32px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + 项目中没有找到任何墙。 + + + 成功 + + + 找到了 {0} 面墙。 + \ No newline at end of file diff --git a/RevitGenTest/RevitAddin.cs b/RevitGenTest/RevitAddin.cs index bbea316..edb4799 100644 --- a/RevitGenTest/RevitAddin.cs +++ b/RevitGenTest/RevitAddin.cs @@ -21,12 +21,12 @@ private void Run() if (walls.Count == 0) { // 如果出现问题,只需设置属性即可 - this.ErrorMessage = "项目中没有找到任何墙。"; + this.ErrorMessage = Properties.Resources.NoWallsFound; this.Result = Result.Failed; return; // 提前返回 } - TaskDialog.Show("成功", $"找到了 {walls.Count} 面墙。"); + TaskDialog.Show(Properties.Resources.SuccessTitle, string.Format(Properties.Resources.FoundWallsMessage, walls.Count)); } } [RevitCommand("我的第一个命令", ToolTip = "这是一个自动生成的酷炫命令!", PanelName = "核心功能", Icon = "Resources/CodeList_32px.png")] @@ -43,12 +43,12 @@ private void Run() if (walls.Count == 0) { // 如果出现问题,只需设置属性即可 - this.ErrorMessage = "项目中没有找到任何墙。"; + this.ErrorMessage = Properties.Resources.NoWallsFound; this.Result = Result.Failed; return; // 提前返回 } - TaskDialog.Show("成功", $"找到了 {walls.Count} 面墙。"); + TaskDialog.Show(Properties.Resources.SuccessTitle, string.Format(Properties.Resources.FoundWallsMessage, walls.Count)); } } } \ No newline at end of file diff --git a/RevitGenTest/RevitGenTest.csproj b/RevitGenTest/RevitGenTest.csproj index be6aa5b..fc9b9d0 100644 --- a/RevitGenTest/RevitGenTest.csproj +++ b/RevitGenTest/RevitGenTest.csproj @@ -29,5 +29,13 @@ ResXFileCodeGenerator Resources.Designer.cs + + RevitGenTest.Properties.Resources + en + + + RevitGenTest.Properties.Resources + ja + \ No newline at end of file