Looking to hire Laravel developers? Try LaraJobs

laravel-thl-pinyin maintained by cawa0505

Description
Romanization tool for Traditional Chinese. A Laravel Wrapper for thl/pinyin
Author
Last update
2019/10/24 09:28 (dev-laravel6)
License
Links
Downloads
61

Comments
comments powered by Disqus

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