overtrue / laravel-pinyin by overtrue

Chinese to Pinyin translator.
474,425
524
13
Package Data
Maintainer Username: overtrue
Maintainer Contact: anzhengchao@gmail.com (overtrue)
Package Create Date: 2015-03-15
Package Last Update: 2024-03-29
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-04-19 15:09:19
Package Statistics
Total Downloads: 474,425
Monthly Downloads: 5,598
Daily Downloads: 326
Total Stars: 524
Total Watchers: 13
Total Forks: 60
Total Open Issues: 7

Laravel-pinyin

Chinese to Pinyin translator for Laravel5 / Lumen based on overtrue/pinyin.

Latest Stable Version Total Downloads Latest Unstable Version License

Install

composer require "overtrue/laravel-pinyin:~3.0"

For Laravel

Add the following line to the section providers of config/app.php:

'providers' => [
    //...
    Overtrue\LaravelPinyin\ServiceProvider::class,
],

as optional, you can use facade:


'aliases' => [
    //...
    'Pinyin' => Overtrue\LaravelPinyin\Facades\Pinyin::class,
],

For Lumen

Add the following line to bootstrap/app.php after // $app->withEloquent();

...
// $app->withEloquent();

$app->register(Overtrue\LaravelPinyin\ServiceProvider::class);
...

Usage

you can get the instance of Overtrue\Pinyin\Pinyin from app container:


$pinyin = app('pinyin');
echo $pinyin->sentence('带着希望去旅行,比到达终点更美好');
// dài zhe xī wàng qù lǔ xíng, bǐ dào dá zhōng diǎn gèng měi hǎo

There are more convenient functions:

| function | method | | ------------- | --------------------------------------------------- | | pinyin() | app('pinyin')->convert() | | pinyin_abbr() | app('pinyin')->abbr() | | pinyin_permalink | app('pinyin')->permalink() | | pinyin_sentence | app('pinyin')->sentence() |

var_dump(pinyin('带着希望去旅行,比到达终点更美好'));
// ["dai", "zhe", "xi", "wang", "qu", "lv", "xing", "bi", "dao", "da", "zhong", "dian", "geng", "mei", "hao"]

var_dump(pinyin_abbr('带着希望去旅行'));
// dzxwqlx
...

Using facade:

use Pinyin; // Facade class, NOT Overtrue\Pinyin\Pinyin

var_dump(Pinyin::convert('带着希望去旅行'));
// ["dai", "zhe", "xi", "wang", "qu", "lv", "xing"]

echo Pinyin::sentence('带着希望去旅行,比到达终点更美好');
// dài zhe xī wàng qù lǔ xíng, bǐ dào dá zhōng diǎn gèng měi hǎo

About overtrue/pinyin specific configuration and use, refer to: overtrue/pinyin

PHP 扩展包开发

想知道如何从零开始构建 PHP 扩展包?

请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— 《PHP 扩展包实战教程 - 从入门到发布》

License

MIT