七楼/yii2-morpher

Yii2 Morpher

安装次数: 69

依赖: 0

建议者: 0

安全: 0

星标: 1

关注者: 2

分支: 1

开放问题: 0

类型:yii2-component

dev-master 2017-04-13 10:29 UTC

This package is not auto-updated.

Last update: 2024-09-15 02:12:26 UTC


README

安装

Latest Stable Version Total Downloads Latest Unstable Version License composer.lock available

安装此扩展的首选方式是通过 composer

运行以下命令之一:

composer require --prefer-dist sevenfloor/yii2-morpher

或者添加以下内容到你的 composer.json 的 require 部分:

"sevenfloor/yii2-morpher": "*"

require

使用方法

'components' => [
   // ...
    'morpher' => [
        'class' => 'sevenfloor\morpher\Morpher'
    ]
    // ...
 ]

获取所有复数形式;

    Yii::$app->morpher
        ->setQuery('Санкт-Петербург')
    ->getData();

     /*result 
     Array
     (
         [Р] => Санкт-Петербурга
         [Д] => Санкт-Петербургу
         [В] => Санкт-Петербург
         [Т] => Санкт-Петербургом
         [П] => Санкт-Петербурге
         [множественное] => Array
             (
                 [И] => Санкт-Петербурги
                 [Р] => Санкт-Петербургов
                 [Д] => Санкт-Петербургам
                 [В] => Санкт-Петербурги
                 [Т] => Санкт-Петербургами
                 [П] => Санкт-Петербургах
             )
     
     ); */

获取单数形式;

    echo Yii::$app->morpher
        ->setQuery('Санкт-Петербург')
        ->setCase(Morpher::PREPOSITIONAL)
    ->getData();
    //result 'Санкт-Петербурге'

获取复数形式;

    echo Yii::$app->morpher
        ->setQuery('Санкт-Петербург')
        ->setCase(Morpher::PREPOSITIONAL)
        ->setPlural()
    ->getData();
    
    //result Санкт-Петербургах