Skip to content

Commit

Permalink
Lumen support.
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Jan 12, 2016
1 parent 5e4d38d commit c3a07ae
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 deletions.
Empty file modified LICENSE
100644 → 100755
Empty file.
30 changes: 27 additions & 3 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Laravel-pinyin

Chinese to Pinyin translator for Laravel 5 based on [overtrue/pinyin](https://github.com/overtrue/pinyin).
Chinese to Pinyin translator for Laravel5 / Lumen based on [overtrue/pinyin](https://github.com/overtrue/pinyin).

[![Latest Stable Version](https://poser.pugx.org/overtrue/laravel-pinyin/v/stable.svg)](https://packagist.org/packages/overtrue/laravel-pinyin) [![Total Downloads](https://poser.pugx.org/overtrue/laravel-pinyin/downloads.svg)](https://packagist.org/packages/overtrue/laravel-pinyin) [![Latest Unstable Version](https://poser.pugx.org/overtrue/laravel-pinyin/v/unstable.svg)](https://packagist.org/packages/overtrue/laravel-pinyin) [![License](https://poser.pugx.org/overtrue/laravel-pinyin/license.svg)](https://packagist.org/packages/overtrue/laravel-pinyin)

Expand All @@ -22,20 +22,44 @@ then
```shell
composer update
```
After completion of the above, add the following line to the section `providers` of `config/app.php`:

## For Laravel

Add the following line to the section `providers` of `config/app.php`:

```php
'Overtrue\LaravelPinyin\ServiceProvider',
```

## Configuration
### config file

you can publish the config file to `config/pinyin.php`:

```php
php artisan vendor:publish --provider="Overtrue\LaravelPinyin\ServiceProvider" --tag="config"
```

## For Lumen

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

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

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

## configuration

| .env | config/pinyin.php | default | description |
| `PINYIN_DELIMITER` | delimiter | `" "` | Symbol for stitching each pinyin. `'-' => dài-zhe-xī-wàng-qù-lǔ-xíng` |
| PINYIN_ACCENT | accent | `true` | Output with tone symbol. |
| PINYIN_ONLY_CHINESE | only_chinese | `true` | Leaving only the Chinese characters. |
| PINYIN_UPPERCASE | uppercase | `true` | Output uppercase(letter) |


## Usage

you can get the instance of `Overtrue\Pinyin\Pinyin` from app container:
Expand Down
Empty file modified composer.json
100644 → 100755
Empty file.
12 changes: 9 additions & 3 deletions src/ServiceProvider.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ class ServiceProvider extends LaravelServiceProvider
*/
public function boot()
{
$this->publishes([
__DIR__ . '/config.php' => config_path('pinyin.php'),
], 'config');
if (function_exists('config_path')) {
$this->publishes([
__DIR__ . '/config.php' => config_path('pinyin.php'),
], 'config');
}
}

/**
Expand All @@ -26,6 +28,10 @@ public function boot()
*/
public function register()
{
$this->mergeConfigFrom(
__DIR__.'/config.php', 'pinyin'
);

Pinyin::settings(config('pinyin', []));

$this->app->singleton('pinyin', function($app)
Expand Down
8 changes: 4 additions & 4 deletions src/config.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
* '': dàizhexīwàngqùlǔxíng
* '-' dài-zhe-xī-wàng-qù-lǔ-xíng
*/
'delimiter' => ' ',
'delimiter' => env('PINYIN_DELIMITER', ' '),

/**
* Output with tone symbol.
*
* true: dài
* false: dai
*/
'accent' => true,
'accent' => env('PINYIN_ACCENT', true),

/**
* Leaving only the Chinese characters.
Expand All @@ -29,10 +29,10 @@
* true: dài zhe xī wàng qù lǔ xíng
* false: dài zhe xī wàng %¥@ qù lǔ xíng
*/
'only_chinese' => false,
'only_chinese' => env('PINYIN_ONLY_CHINESE', true),

/**
* Output uppercase.
*/
'uppercase' => false
'uppercase' => env('PINYIN_UPPERCASE', false)
];
Empty file modified src/helpers.php
100644 → 100755
Empty file.

0 comments on commit c3a07ae

Please sign in to comment.