Skip to content
GitHub

Guides

Use malagasy-intl with your framework

The same payment receipt in TypeScript, React, Vue, Angular, Svelte, Node, Bun and Deno, plain PHP, Laravel and Symfony.

The functions are plain, dependency-free calls, so they work the same in every framework: no plugin, provider or setup step. Each example below writes the same receipt: Ar 150 000, the amount in words, the payer’s number in international format and the date in Malagasy.

Install @mdgascar/malagasy-intl for every module, or only the packages you use (@mdgascar/ariary, @mdgascar/phone-number, @mdgascar/number-words, @mdgascar/date-time). They run in Node.js 22.18+, Bun, Deno and every modern browser, as ESM or CommonJS, with TypeScript types included.

Plain functions, typed options and results. satisfies checks the object without widening it.

receipt.ts
import { formatAriary, spellAriary } from '@mdgascar/ariary';
import { formatPhone } from '@mdgascar/phone-number';
import { formatDate } from '@mdgascar/date-time';
const receipt = {
amount: formatAriary(150000),
words: spellAriary(150000),
phone: formatPhone('0341234567', 'international'),
date: formatDate('2026-11-23', 'full'),
} satisfies Record<string, string>;

Call the functions while rendering: they are pure and fast, so there is nothing to memoize. Works the same in Next.js, Remix and React Native.

Receipt.tsx
import { formatAriary, spellAriary } from '@mdgascar/ariary';
import { formatPhone } from '@mdgascar/phone-number';
import { formatDate } from '@mdgascar/date-time';
export function Receipt({ order }: { order: Order }) {
return (
<dl>
<dd>{formatAriary(order.total)}</dd>
<dd>{spellAriary(order.total)}</dd>
<dd>{formatPhone(order.phone, 'international')}</dd>
<dd>{formatDate(order.paidOn, 'full')}</dd>
</dl>
);
}

Use them straight in the template, with <script setup lang="ts">. Works the same in Nuxt.

Receipt.vue
<script setup lang="ts">
import { formatAriary, spellAriary } from '@mdgascar/ariary';
import { formatPhone } from '@mdgascar/phone-number';
import { formatDate } from '@mdgascar/date-time';
defineProps<{ order: Order }>();
</script>
<template>
<p>{{ formatAriary(order.total) }}</p>
<p>{{ spellAriary(order.total) }}</p>
<p>{{ formatPhone(order.phone, 'international') }}</p>
<p>{{ formatDate(order.paidOn, 'full') }}</p>
</template>

Wrap the calls in computed() signals on a standalone component, or in a pure pipe if you prefer templates.

receipt.component.ts
import { Component, computed, input } from '@angular/core';
import { formatAriary, spellAriary } from '@mdgascar/ariary';
import { formatPhone } from '@mdgascar/phone-number';
import { formatDate } from '@mdgascar/date-time';
@Component({ selector: 'app-receipt', template: '{{ amount() }} · {{ words() }}' })
export class ReceiptComponent {
order = input.required<Order>();
amount = computed(() => formatAriary(this.order().total));
words = computed(() => spellAriary(this.order().total));
phone = computed(() => formatPhone(this.order().phone, 'international'));
date = computed(() => formatDate(this.order().paidOn, 'full'));
}

Call them in markup with Svelte 5 runes. Works the same in SvelteKit.

Receipt.svelte
<script lang="ts">
import { formatAriary, spellAriary } from '@mdgascar/ariary';
import { formatPhone } from '@mdgascar/phone-number';
import { formatDate } from '@mdgascar/date-time';
let { order }: { order: Order } = $props();
</script>
<p>{formatAriary(order.total)}</p>
<p>{spellAriary(order.total)}</p>
<p>{formatPhone(order.phone, 'international')}</p>
<p>{formatDate(order.paidOn, 'full')}</p>

On the server, return the values from any handler. This fetch export runs as is in Bun and Deno, and in Node behind any adapter (Hono, Express…).

server.ts
import { formatAriary, spellAriary } from '@mdgascar/ariary';
import { formatPhone } from '@mdgascar/phone-number';
import { formatDate } from '@mdgascar/date-time';
export default {
fetch: () =>
Response.json({
amount: formatAriary(150000),
words: spellAriary(150000),
phone: formatPhone('0341234567', 'international'),
date: formatDate('2026-11-23', 'full'),
}),
};

PHP 8.3 or later. The core package works in any Composer project; Laravel and Symfony get dedicated packages for validation, templates and database types.

composer require mdgascar/malagasy-intl, then value objects and enums. Works the same in WordPress, Slim, Laminas or any script.

receipt.php
use Mdgascar\MalagasyIntl\Ariary\Ariary;
use Mdgascar\MalagasyIntl\PhoneNumber\{PhoneNumber, PhoneNumberFormat};
use Mdgascar\MalagasyIntl\DateTime\{DateStyle, MalagasyDate};
$receipt = [
'amount' => Ariary::fromInt(150000)->format(),
'words' => Ariary::fromInt(150000)->spell(),
'phone' => PhoneNumber::parse('0341234567')->format(PhoneNumberFormat::International),
'date' => MalagasyDate::fromString('2026-11-23')->format(DateStyle::Full),
];

composer require mdgascar/malagasy-intl-laravel adds Blade directives, Eloquent casts (AsAriary, AsPhoneNumber) and the mg_phone / mg_ariary validation rules. Laravel 12 and 13.

receipt.blade.php
{{-- Order casts: 'total' => AsAriary::class, 'phone' => AsPhoneNumber::class --}}
@use('Mdgascar\MalagasyIntl\PhoneNumber\PhoneNumberFormat')
@use('Mdgascar\MalagasyIntl\DateTime\DateStyle')
<p>@ariary($order->total)</p>
<p>{{ $order->total->spell() }}</p>
<p>@mgPhone($order->phone, PhoneNumberFormat::International)</p>
<p>@mgDate($order->paid_on, DateStyle::Full)</p>

composer require mdgascar/malagasy-intl-symfony adds Twig filters, Doctrine types (mg_ariary, mg_phone) and the #[MalagasyPhone] / #[AriaryAmount] constraints. Symfony 7.4 LTS and 8.

receipt.html.twig
{# Doctrine types: order.total is an Ariary, order.phone a PhoneNumber #}
<p>{{ order.total|ariary }}</p>
<p>{{ order.total.spell }}</p>
<p>{{ order.phone|mg_phone('international') }}</p>
<p>{{ order.paidOn|mg_date('full') }}</p>