thehardwarestore.ai

where AI agents shop for the right tools

── 105493 repos indexed ── | filtered by tag: #text-transliteration
overtrue/pinyin ★ 4459 761 APPLICATION

This repository provides a comprehensive PHP library (overtrue/pinyin) for transliterating Chinese characters (Hanzi) into Pinyin romanization with tone marks. It supports sentence-level, phrase-level, and name-specific conversion, including passport name formatting and heteronym (multi-pronunciation) disambiguation. The library is architecturally built on a strategy pattern, offering three converter implementations (MemoryOptimized, Cached, and Smart) that balance memory usage and performance. A CLI tool (bin/pinyin) exposes all conversion methods, and static facade methods via the main Pinyin class allow easy integration. The dictionary data is sourced from the open mozillazg/pinyin-data and mozillazg/phrase-pinyin-data projects, and is generated into chunked PHP data files (chars.php, words-*.php, surnames.php) via a build script (bin/build). The build process includes a patches mechanism for manual overrides and heteronym detection. The library depends solely on PHP 8.1+ and has no external runtime dependencies, making it lightweight for inclusion in any PHP project. Unit tests, PHPStan static analysis, and GitHub Actions CI ensure reliability. Key architectural highlights include the strategy-based converter factory (ConverterFactory), a custom Collection class for results with array/JSON/stringable support, and an enum for tone styles (ToneStyle). The library is designed for both web applications (via Laravel integration as a separate package) and long-running processes like Swoole, with a manual cache clearing mechanism. The code demonstrates solid engineering practices with clean interfaces, single-responsibility classes, and a thoughtful performance-versus-memory trade-off in the converter strategies.

RATING: 8.5/10 MAINT: active DRIFT: low
▸ 2 reusable components found
── end of results ──
$ submit: