Skip to content

Romanization tool for Traditional Chinese. A Laravel Wrapper of thl/pinyin

License

Notifications You must be signed in to change notification settings

cawa0505/laravel-thl-pinyin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel-thl-pinyin

Romanization tool for Traditional Chinese in Laravel5 / Lumen based on thl/pinyin.

Latest Stable Version Total Downloads Latest Unstable Version License

Install

composer require "cawa0505/laravel-thl-pinyin"

For Laravel if don't discover

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,
],

For Lumen

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

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

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

Usage

instance

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

$pinyin = app('thl-pinyin');
echo $pinyin->bpmf('THL台灣華語羅馬拼音');
// returns "THL ㄊㄞˊ ㄨㄢ ㄏㄨㄚˊ ㄩˇ ㄌㄨㄛˊ ㄇㄚˇ ㄆㄧㄣ ㄧㄣ"

Str Macro

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 ㄊㄞˊ ㄨㄢ ㄏㄨㄚˊ ㄩˇ ㄌㄨㄛˊ ㄇㄚˇ ㄆㄧㄣ ㄧㄣ"
...

helper functions

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 ㄊㄞˊ ㄨㄢ ㄏㄨㄚˊ ㄩˇ ㄌㄨㄛˊ ㄇㄚˇ ㄆㄧㄣ ㄧㄣ"
...

Using facade

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

License

MIT

About

Romanization tool for Traditional Chinese. A Laravel Wrapper of thl/pinyin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages