2017 © Pedro Peláez
 

yii2-extension yii2-inflection

Inflection extension for Yii2. Support for English / Russian languages to inflect words / names / numbers / money / date&time.

image

wapmorgan/yii2-inflection

Inflection extension for Yii2. Support for English / Russian languages to inflect words / names / numbers / money / date&time.

  • Monday, March 26, 2018
  • by wapmorgan
  • Repository
  • 2 Watchers
  • 10 Stars
  • 1,358 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 6 Versions
  • 118 % Grown

The README.md

yii2-inflection

Inflection extension for Yii2. Support for English / Russian languages to inflect words / names / numbers / money / date&time., (*1)

Latest Stable Version License Testing, (*2)

  1. Features
  2. How does it work
  3. Installation

Features

  1. Pluralize word with number:, (*3)

    • en: Yii::$app->inflection->pluralize(2, 'item') => 2 items
    • ru: Yii::$app->inflection->pluralize(2, 'элемент') => 2 элемента
  2. Inflect names to relational cases (applicable in Russian only):, (*4)

    • ru: Yii::$app->inflection->inflectName('Иванов Петр', wapmorgan\yii2inflection\Inflector::DATIVE) => Иванову Петру
    • Description of all supported cases are in Cases section.
  3. Inflect geographical names to relational cases (applicable in Russian only):, (*5)

    • ru: Yii::$app->inflection->inflectGeoName('Санкт-Петербург', wapmorgan\yii2inflection\Inflector::GENITIVE) => Санкт-Петербурга
  4. Generate cardinal numerals:, (*6)

    • en: Yii::$app->inflection->cardinalize(2) => 'two'
    • ru: Yii::$app->inflection->cardinalize(2) => 'два'
  5. Generate ordinal numerals:, (*7)

    • en: Yii::$app->inflection->ordinalize(2) => '2nd'
    • ru: Yii::$app->inflection->ordinalize(2) => '2-й'

    And full form:, (*8)

  • en: Yii::$app->inflection->ordinalize(2, wapmorgan\yii2inflection\Inflector::FULL) => 'second'
  • ru: Yii::$app->inflection->ordinalize(2, wapmorgan\yii2inflection\Inflector::FULL) => 'второй'
  1. Money to words:, (*9)

    • (WIP) en: Yii::$app->inflection->monetize(wapmorgan\yii2inflection\Inflector::DOLLAR, 122.04) => 'one hundred twenty-two dollars four cents'
    • ru: Yii::$app->inflection->monetize(wapmorgan\yii2inflection\Inflector::DOLLAR, 122.04) => 'сто двадцать два доллара четыре цента'
    • Description of all supported currencies are in Currencies section.
  2. Data range to words:, (*10)

    • en: Yii::$app->inflection->textizeTimeRange(new DateInterval('P2Y')) => '2 years'
    • ru: Yii::$app->inflection->textizeTimeRange(new DateInterval('P2Y')) => '2 года'

WIP means Work-in-progress i.e this feature is not supported now, but planned to be implemented., (*11)

Cases

Case Russian
Inflector::NOMINATIVE Именительный
Inflector::ABLATIVE Творительный
Inflector::ACCUSATIVE Винительный
Inflector::AVERSIVE
Inflector::BENEFACTIVE
Inflector::CAUSAL
Inflector::COMITATIVE
Inflector::DATIVE Дательный
Inflector::DISTRIBUTIVE
Inflector::GENITIVE Родительный
Inflector::ORNATIVE
Inflector::POSSESSED
Inflector::POSSESSIVE
Inflector::PREPOSITIONAL Предложный
Inflector::PRIVATIVE
Inflector::SEMBLATIVE
Inflector::SOCIATIVE

Currencies

Currency
Inflector::DOLLAR
Inflector::EURO
Inflector::YEN
Inflector::POUND
Inflector::FRANC
Inflector::YUAN
Inflector::KRONA
Inflector::PESO
Inflector::WON
Inflector::LIRA
Inflector::RUBLE
Inflector::RUPEE
Inflector::REAL
Inflector::RAND
Inflector::HRYVNIA

How does it work

It uses built-in inflector for English pluralization (yii\helpers\Inflector) and Morphos for English & Russian on-the-fly inflection (without dictionaries)., (*12)

Installation

  1. Install extension, (*13)

    composer require wapmorgan/yii2-inflection
    
  2. Add wapmorgan\yii2inflection\Inflection as a service inflection in config and specify proper target language of your application (web.php or console.php):, (*14)

    $config = [
    // ...
    'language' => 'ru_RU', // for example, Russian
    // ...
    'components' => [
      // ...
      'inflection' => [
        'class' => 'wapmorgan\yii2inflection\Inflection'
      ]
    ],
    // ...
    ];
    
  • Optional service parameters:
    • language - default language for inflection. By default, it uses language parameter of current application, but you can change this behavior. Currently supported langs is ru (Russian) and en (English) or their's modification (ru_RU, en_US). If you pass unsupported or unknown language, an Exception will be thrown during service initializion.
    • defaultCurrency - default currency when converting money to words. If set, you can call monetize(float $value) without currency: Yii::$app->inflection->monetize(123.45) => сто двадцать три рубля сорок пять копеек
  1. Call any methods described above in a controller / command / view., (*15)

    $word = 'новость';
    echo Yii::$app->inflection->pluralize(rand(2, 139), $word).PHP_EOL;
    echo Yii::$app->inflection->pluralize(rand(9, 69), $word).PHP_EOL;
    

The Versions

26/03 2018

dev-master

9999999-dev

Inflection extension for Yii2. Support for English / Russian languages to inflect words / names / numbers / money / date&time.

  Sources   Download

GPLv3 GPL-3.0-only

The Requires

 

The Development Requires

yii2 russian english inflection

26/03 2018

1.0.4

1.0.4.0

Inflection extension for Yii2. Support for English / Russian languages to inflect words / names / numbers / money / date&time.

  Sources   Download

GPL-3.0-only

The Requires

 

The Development Requires

yii2 russian english inflection

28/01 2018

1.0.3

1.0.3.0

Inflection extension for Yii2. Support for English / Russian languages to inflect words / names / numbers / money / date&time.

  Sources   Download

GPL-3.0-only

The Requires

 

The Development Requires

yii2 russian english inflection

26/08 2017

1.0.2

1.0.2.0

Inflection extension for Yii2. Support for English / Russian languages to inflect words / names / numbers / money / date&time.

  Sources   Download

GPLv3

The Requires

 

yii2 russian english inflection

14/08 2017

1.0.1

1.0.1.0

Inflection extension for Yii2. Support for English / Russian languages to inflect words / names / numbers / money / date&time.

  Sources   Download

GPLv3

The Requires

 

yii2 russian english inflection

12/08 2017

1.0.0

1.0.0.0

Inflection extension for Yii2. Support for English / Russian languages to inflect words / names / numbers / money / date&time.

  Sources   Download

GPLv3

The Requires

 

yii2 russian english inflection