Installation
Get started with malagasy-intl for Symfony
mdgascar/malagasy-intl-symfony adds validation constraints, Twig filters and Doctrine types on top of the PHP package. Symfony 7.4 LTS and 8, PHP 8.3+.
Installing in a Symfony app
Section titled “Installing in a Symfony app”-
Require the bundle
Section titled “Require the bundle”Terminal composer require mdgascar/malagasy-intl-symfonyWith Symfony Flex the bundle is enabled for you; otherwise add
Mdgascar\MalagasyIntlBundle\MalagasyIntlBundle::class => ['all' => true]toconfig/bundles.php. It brings inmdgascar/malagasy-intl, so every class from Using Composer works too. -
Validate input
Section titled “Validate input”src/Dto/OrderInput.php use Mdgascar\MalagasyIntlBundle\Validator\AriaryAmount;use Mdgascar\MalagasyIntlBundle\Validator\MalagasyPhone;use Symfony\Component\Validator\Constraints as Assert;final class OrderInput{#[Assert\NotBlank, MalagasyPhone]public ?string $phone = null;#[Assert\NotBlank, AriaryAmount]public ?string $total = null;}MalagasyPhonepasses for034 12 345 67or+261 34 12 345 67and fails for031 12 345 67.AriaryAmountpasses forAr 1 500,1 500,50or1500from JSON. Messages come in English and French. -
Store value objects with Doctrine
Section titled “Store value objects with Doctrine”src/Entity/Order.php use Doctrine\ORM\Mapping as ORM;use Mdgascar\MalagasyIntl\Ariary\Ariary;use Mdgascar\MalagasyIntl\PhoneNumber\PhoneNumber;#[ORM\Column(type: 'mg_phone')] // stored as +261341234567public ?PhoneNumber $phone = null;#[ORM\Column(type: 'mg_ariary', precision: 20, scale: 2)]public ?Ariary $total = null; -
Print values in Twig
Section titled “Print values in Twig”templates/order/show.html.twig {{ order.total|ariary }} {# Ar 1 500 #}{{ order.phone|mg_phone }} {# 034 12 345 67 #}{{ 2026|mg_spell }} {# enina amby roapolo sy roa arivo #}{{ 30000000|mg_spell('traditional') }} {# telo safatsiroa #}{{ order.createdAt|mg_date }} {# 27 Novambra 2026 #}mg_phone,mg_dateandmg_spelltake a name:mg_phone('international'),mg_date('numeric'),mg_spell('traditional')(one name per power of ten). Each filter prints nothing fornull.
Configuration
Section titled “Configuration”Only Ariary amounts have options.
malagasy_intl: ariary: grouping: space # space, dot or comma symbol_position: before # before or after decimal: comma # comma or dotA wrong value fails when the container is built, with the option named.