-
Notifications
You must be signed in to change notification settings - Fork 0
Add multi-language support (zh-CN / en / ja) to RevitGenTest #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| using System; | ||
| using System.Globalization; | ||
| using System.IO; | ||
| using System.Threading; | ||
|
|
||
| namespace RevitGenTest | ||
| { | ||
| /// <summary> | ||
| /// Manages language/locale preferences for the addin. | ||
| /// Supports zh-CN (Chinese), en (English), and ja (Japanese). | ||
| /// </summary> | ||
| 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"); | ||
|
|
||
| /// <summary> | ||
| /// The language codes supported by this addin. | ||
| /// </summary> | ||
| public static readonly string[] SupportedLanguages = { "zh-CN", "en", "ja" }; | ||
|
|
||
| /// <summary> | ||
| /// Gets the current UI language code. | ||
| /// </summary> | ||
| public static string CurrentLanguage => Thread.CurrentThread.CurrentUICulture.Name; | ||
|
|
||
| /// <summary> | ||
| /// 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. | ||
| /// </summary> | ||
| 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 | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Saves the language preference to disk so it persists across sessions. | ||
| /// </summary> | ||
| /// <param name="languageCode">The BCP 47 language code to save (e.g. "zh-CN", "en", "ja").</param> | ||
| 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 | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Switches the UI language to the specified culture code and saves the preference. | ||
| /// </summary> | ||
| /// <param name="languageCode">The BCP 47 language code to apply (e.g. "zh-CN", "en", "ja").</param> | ||
| 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 | ||
| } | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <root> | ||
| <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> | ||
| <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> | ||
| <xsd:element name="root" msdata:IsDataSet="true"> | ||
| <xsd:complexType> | ||
| <xsd:choice maxOccurs="unbounded"> | ||
| <xsd:element name="metadata"> | ||
| <xsd:complexType> | ||
| <xsd:sequence> | ||
| <xsd:element name="value" type="xsd:string" minOccurs="0" /> | ||
| </xsd:sequence> | ||
| <xsd:attribute name="name" use="required" type="xsd:string" /> | ||
| <xsd:attribute name="type" type="xsd:string" /> | ||
| <xsd:attribute name="mimetype" type="xsd:string" /> | ||
| <xsd:attribute ref="xml:space" /> | ||
| </xsd:complexType> | ||
| </xsd:element> | ||
| <xsd:element name="assembly"> | ||
| <xsd:complexType> | ||
| <xsd:attribute name="alias" type="xsd:string" /> | ||
| <xsd:attribute name="name" type="xsd:string" /> | ||
| </xsd:complexType> | ||
| </xsd:element> | ||
| <xsd:element name="data"> | ||
| <xsd:complexType> | ||
| <xsd:sequence> | ||
| <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | ||
| <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> | ||
| </xsd:sequence> | ||
| <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> | ||
| <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> | ||
| <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> | ||
| <xsd:attribute ref="xml:space" /> | ||
| </xsd:complexType> | ||
| </xsd:element> | ||
| <xsd:element name="resheader"> | ||
| <xsd:complexType> | ||
| <xsd:sequence> | ||
| <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | ||
| </xsd:sequence> | ||
| <xsd:attribute name="name" type="xsd:string" use="required" /> | ||
| </xsd:complexType> | ||
| </xsd:element> | ||
| </xsd:choice> | ||
| </xsd:complexType> | ||
| </xsd:element> | ||
| </xsd:schema> | ||
| <resheader name="resmimetype"> | ||
| <value>text/microsoft-resx</value> | ||
| </resheader> | ||
| <resheader name="version"> | ||
| <value>2.0</value> | ||
| </resheader> | ||
| <resheader name="reader"> | ||
| <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
| </resheader> | ||
| <resheader name="writer"> | ||
| <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
| </resheader> | ||
| <data name="NoWallsFound" xml:space="preserve"> | ||
| <value>No walls found in the project.</value> | ||
| </data> | ||
| <data name="SuccessTitle" xml:space="preserve"> | ||
| <value>Success</value> | ||
| </data> | ||
| <data name="FoundWallsMessage" xml:space="preserve"> | ||
| <value>Found {0} wall(s).</value> | ||
| </data> | ||
| </root> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <root> | ||
| <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> | ||
| <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> | ||
| <xsd:element name="root" msdata:IsDataSet="true"> | ||
| <xsd:complexType> | ||
| <xsd:choice maxOccurs="unbounded"> | ||
| <xsd:element name="metadata"> | ||
| <xsd:complexType> | ||
| <xsd:sequence> | ||
| <xsd:element name="value" type="xsd:string" minOccurs="0" /> | ||
| </xsd:sequence> | ||
| <xsd:attribute name="name" use="required" type="xsd:string" /> | ||
| <xsd:attribute name="type" type="xsd:string" /> | ||
| <xsd:attribute name="mimetype" type="xsd:string" /> | ||
| <xsd:attribute ref="xml:space" /> | ||
| </xsd:complexType> | ||
| </xsd:element> | ||
| <xsd:element name="assembly"> | ||
| <xsd:complexType> | ||
| <xsd:attribute name="alias" type="xsd:string" /> | ||
| <xsd:attribute name="name" type="xsd:string" /> | ||
| </xsd:complexType> | ||
| </xsd:element> | ||
| <xsd:element name="data"> | ||
| <xsd:complexType> | ||
| <xsd:sequence> | ||
| <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | ||
| <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> | ||
| </xsd:sequence> | ||
| <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> | ||
| <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> | ||
| <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> | ||
| <xsd:attribute ref="xml:space" /> | ||
| </xsd:complexType> | ||
| </xsd:element> | ||
| <xsd:element name="resheader"> | ||
| <xsd:complexType> | ||
| <xsd:sequence> | ||
| <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | ||
| </xsd:sequence> | ||
| <xsd:attribute name="name" type="xsd:string" use="required" /> | ||
| </xsd:complexType> | ||
| </xsd:element> | ||
| </xsd:choice> | ||
| </xsd:complexType> | ||
| </xsd:element> | ||
| </xsd:schema> | ||
| <resheader name="resmimetype"> | ||
| <value>text/microsoft-resx</value> | ||
| </resheader> | ||
| <resheader name="version"> | ||
| <value>2.0</value> | ||
| </resheader> | ||
| <resheader name="reader"> | ||
| <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
| </resheader> | ||
| <resheader name="writer"> | ||
| <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
| </resheader> | ||
| <data name="NoWallsFound" xml:space="preserve"> | ||
| <value>プロジェクトに壁が見つかりませんでした。</value> | ||
| </data> | ||
| <data name="SuccessTitle" xml:space="preserve"> | ||
| <value>成功</value> | ||
| </data> | ||
| <data name="FoundWallsMessage" xml:space="preserve"> | ||
| <value>{0} 個の壁が見つかりました。</value> | ||
| </data> | ||
| </root> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In SDK-style .csproj projects, .resx files are already included as
EmbeddedResourceby default. Adding them again withIncludecan trigger MSBuild “Duplicate EmbeddedResource items” errors. Prefer usingEmbeddedResource Update="Properties\Resources.en.resx"/Update="Properties\Resources.ja.resx"to attachCulture/ManifestResourceNamemetadata without duplicating the items (similar to howResources.resxis handled above).