Chinese to Pinyin translator for Laravel5 / Lumen based on overtrue/pinyin.

Overview

Laravel-pinyin

Chinese to Pinyin translator for Laravel5 / Lumen based on overtrue/pinyin.

Latest Stable Version Total Downloads Latest Unstable Version License

Install

composer require "overtrue/laravel-pinyin:~4.0"

For Laravel

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

'providers' => [
    //...
    Overtrue\LaravelPinyin\ServiceProvider::class,
],

as optional, you can use facade:

'aliases' => [
    //...
    'Pinyin' => Overtrue\LaravelPinyin\Facades\Pinyin::class,
],

For Lumen

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

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

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

Usage

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

$pinyin = app('pinyin');
echo $pinyin->sentence('带着希望去旅行,比到达终点更美好');
// dài zhe xī wàng qù lǔ xíng, bǐ dào dá zhōng diǎn gèng měi hǎo

There are more convenient functions:

function method
pinyin() app('pinyin')->convert()
pinyin_abbr() app('pinyin')->abbr()
pinyin_permalink app('pinyin')->permalink()
pinyin_sentence app('pinyin')->sentence()
var_dump(pinyin('带着希望去旅行,比到达终点更美好'));
// ["dai", "zhe", "xi", "wang", "qu", "lv", "xing", "bi", "dao", "da", "zhong", "dian", "geng", "mei", "hao"]

var_dump(pinyin_abbr('带着希望去旅行'));
// dzxwqlx
...

Using facade:

use Pinyin; // Facade class, NOT Overtrue\Pinyin\Pinyin

var_dump(Pinyin::convert('带着希望去旅行'));
// ["dai", "zhe", "xi", "wang", "qu", "lv", "xing"]

echo Pinyin::sentence('带着希望去旅行,比到达终点更美好');
// dài zhe xī wàng qù lǔ xíng, bǐ dào dá zhōng diǎn gèng měi hǎo

About overtrue/pinyin specific configuration and use, refer to: overtrue/pinyin

PHP 扩展包开发

想知道如何从零开始构建 PHP 扩展包?

请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— 《PHP 扩展包实战教程 - 从入门到发布》

License

MIT

Comments
  • 关于低版本升级后出错

    关于低版本升级后出错

    123

    我的laravel是5.0的,由于当初使用的是laravel-pinyin的低版本,今天composer更新的时候,发现被自动更新到了高版本,导致出错。虽然我强行使用了低版本但是错误仍然存在,我猜测是不是图片中我框出来的那个对于overtrue/pinyin依赖的版本问题,因为本地的overtrue/pinyin是版本并不是与之匹配的低版本。

    很感谢您的代码解决了我的拼音问题,帮忙看一下这个问题嘛,谢谢。

    opened by Tobess 8
  • $this->loader 增加个配置项 可配置默认加载方式就更好啦

    $this->loader 增加个配置项 可配置默认加载方式就更好啦

    Overtrue\Pinyin\Pinyin

    /**

    • Constructor.
    • @param string $loaderName */ public function __construct($loaderName = null) { // 这里的默认加载方式 增加一个配置文件 支持可配置就更完美啦 $this->loader = $loaderName ?: 'Overtrue\Pinyin\FileDictLoader'; }
    opened by daixinguo 2
  • 设置大写无效

    设置大写无效

    我配置文件是使用小写的,间隔符号是:"-",我临时更改配置,间隔符号生效了,但是大写设置没有生效。

                Pinyin::settings([
                    'delimiter' => ' ',
                    'uppercase' => TRUE
                ]);
    
                echo Pinyin::trans('中国');exit;
    

    上面代码,输出小写的:zhong guo

    opened by liuyami 1
  • Upgrade to GitHub-native Dependabot

    Upgrade to GitHub-native Dependabot

    Dependabot Preview will be shut down on August 3rd, 2021. In order to keep getting Dependabot updates, please merge this PR and migrate to GitHub-native Dependabot before then.

    Dependabot has been fully integrated into GitHub, so you no longer have to install and manage a separate app. This pull request migrates your configuration from Dependabot.com to a config file, using the new syntax. When merged, we'll swap out dependabot-preview (me) for a new dependabot app, and you'll be all set!

    With this change, you'll now use the Dependabot page in GitHub, rather than the Dependabot dashboard, to monitor your version updates, and you'll configure Dependabot through the new config file rather than a UI.

    If you've got any questions or feedback for us, please let us know by creating an issue in the dependabot/dependabot-core repository.

    Learn more about migrating to GitHub-native Dependabot

    Please note that regular @dependabot commands do not work on this pull request.

    dependencies 
    opened by dependabot-preview[bot] 0
  •  README.md 错误

    README.md 错误

    README.md 说明错误

    'Overtrue\LaravelPinyin\ServiceProvider' => 'Overtrue\LaravelPinyin\ServiceProvider::class';

    PINYIN_UPPERCASE 的 default value 为 false

    opened by springjk 0
  • Incorrect return type in helpers.php

    Incorrect return type in helpers.php

    helpers.php

    if (! function_exists('pinyin')) {
        /**
         * Get the Pinyin of given string.
         *
         * @param  string $string
         * @param  string $option
         *
         * @return string
         */
        function pinyin($string, $option = Pinyin::NONE)
        {
            return app(Pinyin::class)->convert($string, $option);
        }
    } else {
        Log::warning('There exist multiple function "pinyin".');
    }
    

    Incorrect return type - should return array

    opened by iforwms 0
  • 助手函数 pinyin()报错

    助手函数 pinyin()报错

    pinyin()助手函数调用方法 function pinyin($string, $option = Pinyin::NONE){}, 这个Pinyin::NONE 没有这个常量,可用的option有PINYIN_DEFAULT,PINYIN_TONE,PINYIN_NO_TONE,PINYIN_ASCII_TONE,PINYIN_NAME等等, 没有NONE,overtrue/laravel-pinyin版本为4.0.0, overtrue/pinyin版本为4.0.5

    opened by xin6841414 2
Releases(4.0.0)
Owner
安正超
Keep calm and coding.
安正超
📦 Adds Laravel Packages Support to Lumen and Vendor Publish Artisan Command.

Laravel Package Support for Lumen: Makes Lumen compatible with Laravel Packages. You can use any Laravel Packages in Lumen by installing Larasupport Package.

Irfaq Syed 127 Dec 17, 2022
A collection of generators for Lumen and Laravel 5.

Lumen generators A collection of generators for Lumen and Laravel 5. Contents Why ? Installation Quick Usage Detailed Usage Model Generator Migration

Amine Ben hammou 349 Mar 24, 2022
CORS (Cross-Origin Resource Sharing) support for Laravel and Lumen

Description This package adds Cross-Origin Resource Sharing (CORS) support to your Laravel application. The package is based on Framework agnostic (PS

null 48 Feb 1, 2020
A Laravel and Lumen Badges Generator

Laravel and Lumen Badge Generator That package is a easy wrapper to Badges/Poser. #Installing composer require vluzrmos/laravel-badge-poser Laravel co

Vagner Luz do Carmo 6 Jun 10, 2020
Provides a Eloquent query builder for Laravel or Lumen

This package provides an advanced filter for Laravel or Lumen model based on incoming requets.

M.Fouladgar 484 Jan 4, 2023
Stripe integration in Lumen

Lumen Boilerplate/Starter App for Stripe payment processing Core Features return all available subscription plans create a subscription check subscrip

George Basteas 3 Jan 3, 2022
Laravel and Lumen Auto Hard Deleter

Laravel Auto Hard Deleter This package deletes soft deleted rows automatically after a time interval that you define. For Laravel and Lumen 6, 7, 8 In

Siavash Bamshadnia 38 Dec 28, 2022
Public API for the project coding.events. Made in PHP 8.0 with Lumen 8, PHP-FPM, NGINX and MySQL 8.

coding.events API Uma API feita apenas para passar o tempo, montando uma API para o site <coding.events>. Sinta-se livre para usar esse código como es

Kaique Garcia 3 Oct 9, 2022
A Slack Invitator made with Lumen Framework.

Lumen - Slackin A Slack Invitator made with Lumen Framework and inspired by rauchg/slackin. That application uses some of my awesome packages: Badge P

Vagner Luz do Carmo 56 May 3, 2020
Laravel Lumen service provider for Understand.io

The service provider is deprecated - it does not support error grouping. Laravel Lumen service provider for Understand.io You may also be interested i

null 6 May 30, 2019
🔐 JSON Web Token Authentication for Laravel & Lumen

Documentation Documentation for 1.* here For version 0.5.* See the WIKI for documentation. Supported by Auth0 If you want to easily add secure authent

Sean Tymon 10.7k Jan 3, 2023
Lumen rest api demo with Dingo/Api, JWT, CORS, PHPUNIT

lumen-api-demo 这是一个比较完整用 lumen 5.7 写的的 REST API 例子。使用了 dingo/api ,jwt 实现登录,功能上很简单,登录,注册,发帖,评论,单元测试(正在补充)。 lumen5.x 请看对应的分支 有需要随时联系我 lumen/laravel/rest

Yu Li 859 Oct 25, 2022
Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with Firebase Cloud Messaging (FCM).

Laravel-FCM Introduction Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with Firebase Cloud M

Rahul Thapa 2 Oct 16, 2022
Cascade delete and restore when using the Laravel or Lumen SoftDeletes feature.

Cascade delete and restore when using the Laravel or Lumen SoftDeletes feature.

Asked.io 669 Nov 30, 2022
Simple Video is a automated H264 encryption system built on Lumen Laravel Framework

Simple Video is a automated H264 encryption system built on Lumen Laravel Framework

Azril Nazli Alias 4 Oct 5, 2022
Enable/disable query logger in Laravel/Lumen

Enable/disable query logger in Laravel/Lumen

Ngoc Linh Pham 5 Nov 2, 2022
Laravel Responder - a package for building API responses, integrating Fractal into Laravel and Lumen

A Laravel Fractal package for building API responses, giving you the power of Fractal with Laravel's elegancy.

Alexander Tømmerås 776 Dec 25, 2022
Simple solution for form request validation on lumen.

Form Request Validation for Lumen This small package contains a laravel-like solution for request form validation. Contents Form Request Validation fo

Samuel Nunes de Souza 5 Nov 4, 2022
create API-LUMEN

Lumen PHP Framework Laravel Lumen is a stunningly fast PHP micro-framework for building web applications with expressive, elegant syntax. We believe d

L. Yasril Imam 3 Nov 25, 2022