hekmatinasser/notowo
Laravel package for converting numbers to Persian (Farsi) and Arabic words. Includes helpers for spelling out amounts (e.g., in invoices), formatting digits, and handling different locales/scripts for readable, localized output.
Installation:
composer require hekmatinasser/notowo
Add the service provider in config/app.php (if not auto-discovered):
'providers' => [
// ...
Hekmatinasser\Notowo\NotowoServiceProvider::class,
],
Basic Usage: Convert a number to its word representation:
use Hekmatinasser\Notowo\Notowo;
$notowo = new Notowo;
echo $notowo->convert(1234); // Output: "One Thousand Two Hundred Thirty Four"
First Use Case:
Dynamic Number Conversion:
$amount = 5000.50;
echo Notowo::convert($amount, 'en'); // "Five Thousand and Fifty Cents"
123.45 → "One Hundred Twenty Three and Forty Five Cents").Language Support:
Notowo::convert(1000, 'fa'); // Farsi/Persian output
config/notowo.php for available locales (e.g., en, fa).Integration with Laravel:
app/Helpers.php:
if (!function_exists('number_to_words')) {
function number_to_words($number, $locale = 'en') {
return Notowo::convert($number, $locale);
}
}
$request->validate(['amount' => 'required|numeric']);
$formattedAmount = number_to_words($request->amount);
Custom Templates: Override default word templates (e.g., for currencies):
Notowo::setTemplate('en', [
'decimal' => 'Dollars and {0} Cents',
// ... other keys
]);
Locale Limitations:
en (English) and fa (Farsi) out-of-the-box. Extending requires manual template updates.Decimal Handling:
. (e.g., 123.45). Use number_format() for locale-specific decimals:
$formatted = number_format($amount, 2, ',', ' ');
Notowo::convert($formatted, 'en');
Large Numbers:
$cacheKey = "notowo_{$number}_{$locale}";
return cache()->remember($cacheKey, now()->addHours(1), function() use ($number, $locale) {
return Notowo::convert($number, $locale);
});
Config Overrides:
config/notowo.php require reloading the config:
$this->app['config']->set('notowo', $customConfig);
config/notowo.php for missing keys or typos in custom templates.'en' vs 'en_US').0 → "Zero").false by default; handle manually).Add New Locales:
Notowo class or create a decorator:
class ExtendedNotowo extends Notowo {
public function convert($number, $locale = 'es') {
if ($locale === 'es') {
$this->setTemplate('es', [...]);
}
return parent::convert($number, $locale);
}
}
Custom Number Formats:
setTemplate() to modify separators or word order:
Notowo::setTemplate('en', [
'separator' => ' ',
'decimal' => '{0} Dollars {1} Cents',
]);
Testing:
Notowo class in PHPUnit:
$mock = $this->createMock(Notowo::class);
$mock->method('convert')->willReturn('Test Output');
How can I help you explore Laravel packages today?