overtrue / php-opencc
中文简繁转换,支持词汇级别的转换、异体字转换和地区习惯用词转换(中国大陆、台湾、香港、日本新字体)。基于 [BYVoid/OpenCC](https://github.com/BYVoid/OpenCC) 数据实现。
Fund package maintenance!
overtrue
Installs: 4 311
Dependents: 0
Suggesters: 0
Security: 0
Stars: 80
Watchers: 2
Forks: 13
Open Issues: 0
Requires
- php: >=8.0
- ext-zip: *
- symfony/console: ^5.4|^6.3
- symfony/process: ^5.4|^6.3
Requires (Dev)
- brainmaestro/composer-git-hooks: dev-master
- jetbrains/phpstorm-attributes: ^1.0
- laravel/pint: ^0.1|^1.10
- mockery/mockery: ^1.2
- phpunit/phpunit: ^9.0
- vimeo/psalm: ^4.10
This package is auto-updated.
Last update: 2024-11-13 13:35:11 UTC
README
中文简繁转换,支持词汇级别的转换、异体字转换和地区习惯用词转换(中国大陆、台湾、香港、日本新字体)。基于 BYVoid/OpenCC 数据实现。
安装
$ composer require overtrue/php-opencc -vvv
使用
use Overtrue\PHPOpenCC\OpenCC; echo OpenCC::convert('服务器', 'SIMPLIFIED_TO_TAIWAN_WITH_PHRASE'); // output: 伺服器
使用策略别名
use Overtrue\PHPOpenCC\OpenCC; use Overtrue\PHPOpenCC\Strategy; // 以下方法等价: // 方法 echo OpenCC::s2tw('服务器'); echo OpenCC::simplifiedToTaiwan('服务器'); // 字符串 echo OpenCC::convert('服务器', 's2tw'); echo OpenCC::convert('服务器', 'S2TW'); echo OpenCC::convert('服务器', 'SIMPLIFIED_TO_TAIWAN'); // 常量 echo OpenCC::convert('服务器', Strategy::S2TW); echo OpenCC::convert('服务器', Strategy::SIMPLIFIED_TO_TAIWAN);
转换策略
在命令行使用
$ php vendor/bin/opencc "汉字" s2tw
说明:
$ php vendor/bin/opencc --help Description: 中文简繁转换,支持词汇级别的转换、异体字转换和地区习惯用词转换(中国大陆、台湾、香港、日本新字体)。 Usage: convert <string> [<strategy>] Arguments: string 待转换的字符串 strategy 转换策略 [default: "SIMPLIFIED_TO_TRADITIONAL"]
❤️ 赞助我
如果你喜欢我的项目并想支持它,点击这里 ❤️
Project supported by JetBrains
Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.
参与贡献
You can contribute in one of three ways:
- File bug reports using the issue tracker.
- Answer questions or fix bugs on the issue tracker.
- Contribute new features or update the wiki.
The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.
License
MIT