wapmorgan/morphos-twig

Adds a {{ plural }}, {{ name }}, {{ numeral }}, {{ ordinal }} and {{ money }} filters to Twig templating engine for Russian pluralization and declenation.

Installs: 29 850

Dependents: 0

Suggesters: 0

Security: 0

Stars: 9

Watchers: 3

Forks: 2

Open Issues: 1

Type:twig-extension

1.6.0 2017-08-15 21:10 UTC

This package is auto-updated.

Last update: 2024-05-09 14:51:27 UTC


README

Latest Stable Version License

Adds {{ plural }}, {{ name }}, {{ numeral }}, {{ ordinal }} and {{ money }} filters to Twig templating engine for Russian pluralization and declenation.

<div>
{{ 'новость'|plural(252) }} от {{ 'Иванов Иван Иванович'|name('родительный') }}
{{ 'сообщение'|numeral(565, 'n') }} и {{ 123.50|money('') }} за Ваше отсутствие
Это Ваше {{ 351|ordinal('n') }} посещение нашего сайта за сегодня!
</div>

Will be compiled in

<div>
252 новости от Иванова Ивана Ивановича
пятьсот шестьдесят пять сообщений и 123 рубля 50 копеек за Ваше отсутствие
Это Ваше триста пятьдесят первое посещение нашего сайта за сегодня!
</div>

Most popular filters:

  • {{ $word|plural($count) }} - Get plural form of word. Just pass count of objects and noun.

    {{ 'новость'|plural(251) }}
  • {{ $value|money($currency) }} - Get money formatted as text string. Just pass value and currency (₽ or $ or € or ₴ or £).

    {{ 123.50|money('р') }}
  • {{ $number|numeral }} - Get cardinal of a number. Just pass number.

    {{ 565|numeral }}
  • {{ $number|ordinal }} - Get ordinal of a number. Just pass number.

    {{ 132|ordinal }}
  • {{ $name|name($case) }} - Get any case of fullname with gender detection.

    {{ 'Иванов Иван Иванович'|name('родительный') }}

Additional filters:

  • {{ $name|name($gender, $case) }} - Get any case of fullname. Just pass name, gender (m or f or null) and case (именительный, родительный, дательный, винительный, творительный, предложный).

    {{ 'Филимонов Игорь|name('m', 'дательный') }}
  • {{ $number|numeral($gender) }} - Get numeral of a number. Just pass number and gender (m or f or n) to use correct form of gender-dependent words (один/одно/одна, два/две).

    {{ 565|numeral('n') }}
  • {{ $word|numeral($number) }} - Get numeral with a pluralized word. Just pass number and noun.

    {{ 'дом'|numeral(221) }}
  • {{ $word|numeral($number, $gender) }} - Get numeral with a pluralized word. Just pass number, noun and gender (m or f or n) to use correct form of gender-dependent words (один/одно/одна, два/две).

    {{ 'сообщение'|numeral(565, 'n') }}
  • {{ $number|ordinal($gender) }} - Get ordinal of a number. Just pass number and gender (m or f or n) to use correct form of gender-dependent words (первый/первое/первая, второй/второе/вторая, etc).

    {{ 'сообщение'|ordinal('n') }}

Installation

Get the Package

composer require wapmorgan/morphos-twig

Register the Service

Open up your services.php in your app/config folder, and add the following lines:

$container
    ->register('morphos.twig_extension', morphos\MorphosTwigExtension::class)
    ->setPublic(false)
    ->addTag('twig.extension');

or if you using Twig separately from Symfony

$twig = new Twig_Environment($loader);
$twig->addExtension(new morphos\MorphosTwigExtension());