Morphos adapter for Twig
PHP
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
MorphosTwigExtension.php
README.md
composer.json

README.md

MorphosTwig

Composer package Latest Stable Version License

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

<div>
{{ 'новость'|plural(252) }} от {{ 'Иванов Иван Иванович'|name('genetivus') }}
{{ 'сообщение'|numeral(565, 'n') }} и {{ 123.50|money('') }} за Ваше отсутствие
</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.
  • {{ $value|money($currency) }} - Get money formatted as text string. Just pass value and currency (₽ or $ or € or ₴ or £).
  • {{ $number|numeral }} - Get numeral of a number. Just pass number.
  • {{ $name|name($case) }} - Get any case of fullname with gender detection.

Additional filters:

  • {{ $number|numeral($gender) }} - Get numeral of a number. Just pass number and gender (m or f or n).
  • {{ $word|numeral($number) }} - Get numeral with a pluralized word. Just pass number and noun.
  • {{ $word|numeral($number, $gender) }} - Get numeral with a pluralized word. Just pass number, noun and gender (m or f or n).
  • {{ $name|name($gender, $case) }} - Get any case of fullname. Just pass name, gender (m or w or null) and case (genetivus, dativus, accusative, ablativus, praepositionalis).

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());