Romanization tool for Traditional Chinese in Laravel5 / Lumen based on thl/pinyin.
composer require "cawa0505/laravel-thl-pinyin"
Add the following line to the section providers
of config/app.php
:
'providers' => [
//...
THL\LaravelPinyin\ServiceProvider::class,
],
as optional, you can use facade:
'aliases' => [
//...
'Pinyin' => THL\LaravelPinyin\Facades\Pinyin::class,
],
Add the following line to bootstrap/app.php
after // $app->withEloquent();
...
// $app->withEloquent();
$app->register(THL\LaravelPinyin\ServiceProvider::class);
...
you can get the instance of THL\Pinyin
from app container:
$pinyin = app('thl-pinyin');
echo $pinyin->bpmf('THL台灣華語羅馬拼音');
// returns "THL ㄊㄞˊ ㄨㄢ ㄏㄨㄚˊ ㄩˇ ㄌㄨㄛˊ ㄇㄚˇ ㄆㄧㄣ ㄧㄣ"
There are some macro to Str
macro | method |
---|---|
Str::pinyin() |
app('pinyin')->pinyin() |
Str::pinyinSlug() |
app('pinyin')->slug() |
Str::bpmf() |
app('pinyin')->bpmf() |
use Illuminate\Support\Str;
Str::pinyin('THL台灣華語羅馬拼音');
// returns "THL tai2 wan1 hua2 yu3 luo2 ma3 pin1 yin1"
Str::bpmf('THL台灣華語羅馬拼音');
// returns "THL ㄊㄞˊ ㄨㄢ ㄏㄨㄚˊ ㄩˇ ㄌㄨㄛˊ ㄇㄚˇ ㄆㄧㄣ ㄧㄣ"
...
There are some convenient functions:
function | method |
---|---|
pinyin() |
app('pinyin')->pinyin() |
pinyin_slug() |
app('pinyin')->slug() |
bpmf() |
app('pinyin')->bpmf() |
pinyin('THL台灣華語羅馬拼音');
// returns "THL tai2 wan1 hua2 yu3 luo2 ma3 pin1 yin1"
bpmf('THL台灣華語羅馬拼音');
// returns "THL ㄊㄞˊ ㄨㄢ ㄏㄨㄚˊ ㄩˇ ㄌㄨㄛˊ ㄇㄚˇ ㄆㄧㄣ ㄧㄣ"
...
use THL\LaravelPinyin\Facades\Pinyin;
Pinyin::pinyin('THL台灣華語羅馬拼音');
// returns "THL tai2 wan1 hua2 yu3 luo2 ma3 pin1 yin1"
Pinyin::slug('THL台灣華語羅馬拼音');
// returns "thl-tai-wan-hua-yu-luo-ma-pin-yin"
About thl/pinyin
specific configuration and use, refer to: thl/pinyin
MIT