Skip to content

Comments

Feature: Chinese Localization Enhancement and Pinyin Search Support#317

Draft
BIANG-qilie wants to merge 2 commits intoblushiemagic:1.4.4from
BIANG-qilie:1.4.4
Draft

Feature: Chinese Localization Enhancement and Pinyin Search Support#317
BIANG-qilie wants to merge 2 commits intoblushiemagic:1.4.4from
BIANG-qilie:1.4.4

Conversation

@BIANG-qilie
Copy link

Summary

This PR introduces two major enhancements for Chinese users: comprehensive Simplified Chinese localization improvements and a new Pinyin search feature that allows users to search items using Pinyin input methods.

Changes

1. Chinese Localization Enhancement (8a2ccb5)

  • Improved Simplified Chinese translations: Updated and refined Chinese translations throughout the mod
  • Enhanced localization quality: Fixed formatting issues and improved translation accuracy
  • File changes: Updated Localization/zh-Hans.hjson with 333 additions and 331 deletions, representing a comprehensive review and improvement of existing translations

2. Pinyin Search Feature (fd6db47)

  • New Pinyin search functionality: Users can now search for Chinese item names using full Pinyin or Pinyin initials (e.g., "tiekuang" or "tk" for "铁矿(whose Pinyin is "tie kuang")")
  • Configuration option: Added EnablePinyinSearch option in mod configuration, allowing users to enable/disable the feature
  • Smart search logic:
    • Prioritizes direct Chinese character matching for performance
    • Falls back to Pinyin matching when Chinese matching fails
    • Supports both full Pinyin and Pinyin initials matching
  • Performance optimizations:
    • Implements caching mechanism to avoid redundant Pinyin conversions
    • Uses thread-safe ConcurrentDictionary for caching
    • Lazy initialization of NPinyin library to avoid JIT compilation issues
  • Technical implementation:
    • Integrated NPinyin.Core.dll as an embedded resource
    • Implemented reflection-based method invocation to avoid compile-time dependencies
    • Added PreJITFilter to delay JIT compilation until NPinyin is loaded
    • Created PinyinHelper utility class with robust error handling

3. Additional Improvements

  • Code quality: Fixed namespace references (UtilsTerraria.Utils) in AuditEntry.cs and ShimmerResultReports.cs
  • Documentation: All code comments translated to English for consistency
  • Localization: Added Pinyin search configuration text in multiple languages (English, Spanish, French, Polish, Portuguese, Russian, and Simplified Chinese)

Technical Details

Files Changed

  • Common/Utils/PinyinHelper.cs (new, 405 lines): Core Pinyin search utility class
  • MagicStorageMod.cs: Added NPinyin assembly loading logic
  • MagicStorageConfig.cs: Added EnablePinyinSearch configuration option
  • Common/Threading/Refreshing/StorageViewControls.cs: Integrated Pinyin search into item filtering
  • CheckModBuildVersionBeforeJIT.cs: Added JIT filter for Pinyin functionality
  • Localization/zh-Hans.hjson: Comprehensive translation improvements
  • Localization/*.hjson: Added Pinyin search configuration text in all supported languages
  • MagicStorage.csproj: Added NPinyin.Core.dll as embedded resource

Key Features

  1. Automatic language detection: Pinyin search only activates in Simplified Chinese environment
  2. Thread-safe implementation: Uses ConcurrentDictionary and double-checked locking pattern
  3. Robust error handling: Gracefully handles missing NPinyin library or initialization failures
  4. Performance optimized: Caches Pinyin conversions and prioritizes fast Chinese character matching

Testing

  • Verified Pinyin search works correctly with full Pinyin input
  • Verified Pinyin search works correctly with Pinyin initials input
  • Verified Chinese character matching still works as before
  • Verified feature only activates in Simplified Chinese environment
  • Verified configuration option properly enables/disables the feature
  • Tested thread safety in multi-threaded item filtering scenarios

Breaking Changes

None. This is a purely additive feature that maintains backward compatibility.


Note: This PR combines two related features that enhance the experience for Chinese users. The localization improvements provide better translation quality, while the Pinyin search feature adds a convenient way to search items using Pinyin input methods commonly used by Chinese users.

BIANG-qilie and others added 2 commits December 17, 2025 09:40
…lified Chinese (#1)

* feat(i18n): update Chinese localization for Magic Storage mod

* feat(i18n): enhance Chinese localization for Magic Storage mod with new translations and updates

* fix(i18n): correct formatting in Chinese localization for Magic Storage mod

---------

Co-authored-by: biang <leyobiang@gmail.com>
…t method (#2)

* feat(pinyin): Add Pinyin search functionality for Chinese item names

- Introduced a new configuration option to enable Pinyin search in `MagicStorageConfig.cs`.
- Implemented Pinyin search logic in `StorageViewControls.cs`, allowing users to search item names using full Pinyin or initials.
- Added a new utility class `PinyinHelper.cs` for handling Pinyin conversion and caching.
- Updated project references to include `NPinyin.Core` for Pinyin processing.
- Enhanced localization files to support new Pinyin search feature in both English and Simplified Chinese.
- Documented the feature in a new markdown file for clarity on usage and implementation.

* refactor(auditing, shimmering): Update Utils references to use Terraria.Utils

- Changed references from Utils to Terraria.Utils for coin splitting and clamping in AuditEntry.cs and ShimmerResultReports.cs.
- Improved code clarity and consistency by ensuring the correct namespace is used for utility functions.

* feat(pinyin): Integrate NPinyin.Core for enhanced Pinyin search functionality

- Added support for loading NPinyin.Core.dll as an embedded resource to enable Pinyin search capabilities.
- Implemented logic to delay JIT compilation of the ConvertToPinyin method until NPinyin.Core is fully loaded.
- Enhanced PinyinHelper to utilize reflection for method invocation, ensuring compatibility and avoiding direct dependencies.
- Updated localization files to include options for enabling Pinyin search in multiple languages.
- Introduced checks to ensure Pinyin search is only active in a Simplified Chinese environment.

* refactor(pinyin): Simplify method retrieval and enhance error handling in PinyinHelper

- Introduced GetMethodsSafely and FindMethod utility functions to streamline method retrieval and improve error handling.
- Updated PinyinHelper to utilize these new methods, reducing code complexity and enhancing maintainability.
- Added comments for clarity on the purpose and functionality of the new methods.

* refactor(pinyin): Update comments and documentation for clarity in PinyinHelper and MagicStorageMod

* refactor(pinyin): Remove debug logging for Pinyin search feature in MagicStorageMod

* feat(pinyin): Remove Pinyin search documentation file

---------

Co-authored-by: biang <leyobiang@gmail.com>
@BIANG-qilie BIANG-qilie marked this pull request as draft December 17, 2025 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant