Installation
Bien démarrer avec malagasy-intl pour Symfony
mdgascar/malagasy-intl-symfony ajoute des contraintes de validation, des filtres Twig et des types Doctrine au paquet PHP. Symfony 7.4 LTS et 8, PHP 8.3+.
Installer dans une application Symfony
Section intitulée « Installer dans une application Symfony »-
Ajouter le bundle
Section intitulée « Ajouter le bundle »Terminal composer require mdgascar/malagasy-intl-symfonyAvec Symfony Flex, le bundle est activé pour vous ; sinon, ajoutez
Mdgascar\MalagasyIntlBundle\MalagasyIntlBundle::class => ['all' => true]àconfig/bundles.php. Il installe aussimdgascar/malagasy-intl, donc toutes les classes de Avec Composer fonctionnent aussi. -
Valider les saisies
Section intitulée « Valider les saisies »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;}MalagasyPhoneaccepte034 12 345 67ou+261 34 12 345 67et refuse031 12 345 67.AriaryAmountaccepteAr 1 500,1 500,50ou1500venant de JSON. Les messages existent en anglais et en français. -
Enregistrer des objets valeur avec Doctrine
Section intitulée « Enregistrer des objets valeur avec 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; -
Afficher les valeurs dans Twig
Section intitulée « Afficher les valeurs dans 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_dateetmg_spellacceptent un nom :mg_phone('international'),mg_date('numeric'),mg_spell('traditional')(un nom par puissance de dix). Chaque filtre n’affiche rien pournull.
Configuration
Section intitulée « Configuration »Seuls les montants en ariary ont des options.
malagasy_intl: ariary: grouping: space # space, dot or comma symbol_position: before # before or after decimal: comma # comma or dotUne valeur incorrecte échoue à la construction du conteneur, en nommant l’option.