Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Pinyin Laravel Package

overtrue/pinyin

Convert Chinese characters to Pinyin in PHP/Laravel. overtrue/pinyin supports full pinyin, initials, tone options, segmentation, and custom dictionaries—ideal for search indexing, sorting, slugs, and transliteration in web apps.

View on GitHub
Deep Wiki
Context7
6.0.0

🚀 Major Features

  • 性能优化策略系统: 全新的转换策略架构,针对不同使用场景提供最优性能
    • 内存优化策略 (Memory Optimized): 占用 ~400KB 内存,适合 Web 请求和内存受限环境
    • 缓存策略 (Cached): 占用 ~4MB 内存,重复转换性能提升 2-3 倍,适合批处理任务
    • 智能策略 (Smart): 占用 600KB-1.5MB 内存,根据文本复杂度自适应加载
  • ConverterFactory: 新的工厂模式管理转换器实例和策略选择
  • 自动策略选择: 根据运行环境(Web/CLI/内存限制)自动推荐最佳策略
  • 性能基准测试工具: 内置的策略性能对比和监控工具
  • 内存监控: 支持实时监控内存使用情况和性能指标

🔧 API Changes

  • 新增 Pinyin::useMemoryOptimized() - 切换到内存优化策略
  • 新增 Pinyin::useCached() - 切换到缓存策略
  • 新增 Pinyin::useSmart() - 切换到智能策略
  • 新增 Pinyin::useAutoStrategy() - 自动选择最佳策略
  • 新增 Pinyin::clearCache() - 清理所有转换器缓存
  • 新增 ConverterFactory::make($strategy) - 创建指定策略的转换器
  • 新增 ConverterFactory::recommend() - 获取推荐策略
  • 新增 ConverterFactory::getStrategiesInfo() - 获取所有策略信息

⚡ Performance Improvements

  • 内存使用优化: 默认内存占用从 ~4MB 降低到 ~400KB
  • 转换速度提升: 缓存策略下重复转换速度提升 2-3 倍
  • 智能加载: 根据文本复杂度动态调整数据加载策略
  • 按需加载: 内存优化策略仅在需要时加载转换数据

📊 Benchmark & Monitoring

  • 新增 php benchmark/run.php - 运行性能基准测试
  • 新增 php benchmark/compare-strategies.php - 策略对比测试
  • 新增基准测试文档 docs/benchmark-guide.md
  • 支持内存使用情况实时监控

运行基准测试

# 运行标准基准测试,显示所有方法的性能表现
php benchmark/run.php

# 详细的策略对比测试,对比三种策略的性能差异
php benchmark/compare-strategies.php

基准测试会显示:

  • 每种策略的执行时间和内存使用情况
  • 不同文本长度下的性能表现
  • 策略之间的性能对比和推荐场景

🔄 Breaking Changes

  • 默认策略变更: 从全缓存改为内存优化策略,降低默认内存占用
  • 转换器架构重构: 引入策略模式,旧的直接实例化转换器方式仍兼容
  • 性能特征变化: 首次转换可能略慢,但内存占用显著降低

🔧 Backward Compatibility

  • 完全兼容 5.x API,现有代码无需修改即可使用
  • heteronym() 方法(5.3.3+ 引入)继续保持兼容
  • 所有原有的转换方法 (sentence, phrase, chars 等) 保持不变

📚 Documentation

  • 更新 README.md 增加性能优化策略说明
  • 新增性能对比表格和使用建议
  • 新增基准测试指南
  • 新增性能优化最佳实践

🔧 Development Tools

  • 新增性能基准测试脚本
  • 新增策略对比工具
  • 增强命令行工具支持策略选择

https://github.com/overtrue/pinyin/blob/master/CHANGELOG.md

New Contributors

Full Changelog: https://github.com/overtrue/pinyin/compare/5.3.4...6.0.0

5.3.4

What's Changed

New Contributors

Full Changelog: https://github.com/overtrue/pinyin/compare/5.3.3...5.3.4

5.3.3

What's Changed

Full Changelog: https://github.com/overtrue/pinyin/compare/5.3.2...5.3.3

5.3.2

Pinyin::abbr 新增第三个参数 bool $preserveEnglishWords = false, 以保留输入内容的英文单词 #199

Full Changelog: https://github.com/overtrue/pinyin/compare/5.3.1...5.3.2

5.3.1

Fixed 「仆区」应该读 pú ōu 而非 pú qū #200

Full Changelog: https://github.com/overtrue/pinyin/compare/5.3.0...5.3.1

5.3.0

What's Changed

New Contributors

Full Changelog: https://github.com/overtrue/pinyin/compare/5.2.2...5.3.0

5.2.0

What's Changed

Full Changelog: https://github.com/overtrue/pinyin/compare/5.1.1...5.2.0

4.1.0

What's changed

  • 支持轻声替换,解决 #119 #138 问题。

Full Changelog: https://github.com/overtrue/pinyin/compare/4.0.8...4.1.0

5.1.1

What's Changed

  • 支持轻声替换,修复 #119 #138 问题

Full Changelog: https://github.com/overtrue/pinyin/compare/5.1.0...5.1.1

5.1.0

What's Added

  • 新增 Pinyin::passportName(string $name, string $toneStyle = Converter::TONE_STYLE_NONE) 方法,使用 yu 代替 ü 输出。

What's Changed

New Contributors

Full Changelog: https://github.com/overtrue/pinyin/compare/5.0.0...5.1.0

5.0.0

BREAKING CHANGES

Warning Completely refactored version, recommended to read the documentation before use.

4.0.8
4.0.7
4.0.6
4.0.5
4.0.4
4.0.3
4.0.1
4.0.0
3.0.6

Bugfix. #95

3.0.5
  • Bugfix #81
3.0.4
  • Bugfix #58 .
3.0.3
  • Fix space delimiter. #55
3.0.2
  • PHP 5.3 support.
  • Keep numbers in permalink. #54
3.0.1
  • Support name convert. $pinyin->name('xxx'); #48
3.0.0
  • 重新设计的结构
  • 内存占用更少
  • 提供生成工具,便于大家补充词典
  • 新的 API,更贴近使用场景
2.6.8
  • [Bugfix] #39
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
croct/coding-standard
croct/plug-php
nqxcode/phpmorphy
boundwize/pyrameter
testo/facade
develia/commons
dmstr/symfony-system-resources-bundle
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
renatomarinho/laravel-page-speed
develia/geo-bundle
austinheap/laravel-database-encryption
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
imbo/imbo-coding-standard
visualbuilder/filament-lottie
servicioslineaonce/starter-kit
atomcoder/laravel-reorderable
irajul/filament-shadcn-theme