Polyscope - The agent-first dev environment for Laravel

Laravel Pinyin

overtrue/laravel-pinyin image

Laravel Pinyin stats

Downloads
439.2K
Stars
516
Open Issues
7
Forks
57

View on GitHub →

Chinese to Pinyin translator.

Laravel-Pinyin

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

Install

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

For Laravel

(If you are using Laravel >= 5.5, the auto-discovery feature will handle these two steps for you.)

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

:heart: Sponsor me

如果你喜欢我的项目并想支持它,点击这里 :heart:

Project supported by JetBrains

Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.

PHP 扩展包开发

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

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

License

MIT

overtrue photo

Keep calm and coding.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Overtrue Laravel Pinyin Related Articles

Meet LaraUtilX: A Utility Toolkit Every Laravel Developer Needs image

Meet LaraUtilX: A Utility Toolkit Every Laravel Developer Needs

Read article
Native array_first() and array_last() Functions in PHP 8.5 image

Native array_first() and array_last() Functions in PHP 8.5

Read article
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
CodeKudu logo

CodeKudu

Stand-ups, Retrospectives, and 360° Feedback for the entire team. 50% off with code LARAVELNEWS.

CodeKudu
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Honeybadger logo

Honeybadger

Simple developer-focused application monitoring for Laravel. Error tracking, log management, uptime monitoring, status pages, and more!

Honeybadger
Statamic logo

Statamic

The drop-in ready Laravel CMS you’re been waiting for. Go full-stack or headless, flat file or database – it’s up to you.

Statamic
Celebian logo

Celebian

Celebian is a social media marketing agency specializing in helping their clients go viral on TikTok. Whether you're looking to reach a bigger audience or gain more Tiktok followers, likes, and views, they've got you covered.

Celebian