cawa0505/laravel-thl-pinyin

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

dev-laravel6 2019-10-24 07:28 UTC

This package is auto-updated.

Last update: 2024-11-29 05:38:52 UTC


README

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

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:

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