jurchiks / numbers2words_twig
Twig extension for jurchiks/numbers2words
1.0.2
2020-07-22 16:38 UTC
Requires
- php: >=7.4.0
- jurchiks/numbers2words: ^2.4
- twig/twig: ^3.0
Requires (Dev)
- phpunit/phpunit: ^9.2
This package is auto-updated.
Last update: 2024-12-23 02:22:05 UTC
README
Twig extension for jurchiks/numbers2words.
Installation:
composer require jurchiks/numbers2words_twig
Configuration:
use \Twig\Environment; use \js\tools\numbers2words\Speller; use \js\tools\numbers2words\twig\SpellerExtension; $extension = new SpellerExtension(Speller::LANGUAGE_ENGLISH, Speller::CURRENCY_EURO); $extension->requireDecimal = true|false; // default true $extension->spellDecimal = true|false; // default false $twig = new Environment($loader); $twig->addExtension($extension);
To enable the Twig extension in Symfony, add it in config/services.yaml
(or its equivalent):
services: js\tools\numbers2words\twig\SpellerExtension: tags: [twig.extension] arguments: ['en', 'EUR'] properties: # optional requireDecimal: true spellDecimal: false
Usage:
<p>{{ spellNumber(123) }}</p> <p>{{ spellCurrency(123.45) }}</p> <p>{{ spellCurrencyShort(123.45) }}</p> <p>{{ spellNumber(123, 'ru') }}</p> <p>{{ spellCurrency(123.45, null, 'RUR') }}</p>