kwn/number-to-words
Convert numbers and currency amounts to words in PHP. Supports multiple languages via RFC 3066 identifiers, with number and currency transformers. Simple API: create transformers or use static calls to render values like 5120 as “five thousand one hundred twenty”.
## Technical Evaluation
### **Architecture Fit**
- **Lightweight & Modular**: Remains unchanged—package is still a standalone utility with no external dependencies (beyond PHP core). The fix for Hungarian (`hu`) in 3.0.1 is a **non-breaking, locale-specific correction** that doesn’t alter the core architecture.
- **Language Agnostic**: Continues to support 30+ locales, including the newly verified Hungarian (`hu`). Ideal for multilingual Laravel apps, particularly those serving Central/Eastern European markets (e.g., financial platforms, e-commerce with Hungarian support).
- **Isolation**: No risk of side effects; the fix is **contained to the Hungarian transformer** and doesn’t impact other locales or Laravel components.
### **Integration Feasibility**
- **Composer Integration**: Unchanged—still zero-friction (`composer require kwn/number-to-words:^3.0`).
- **Laravel Service Container**: No modifications needed; the Hungarian fix is **backward-compatible**.
- **Blade Directives/API/Console**: Existing integrations remain valid. Example for Hungarian:
```php
@numberToWords(1234, 'hu') // Now correctly outputs "ezerszer-háromszáznegyven"
toCurrencyWords() helper) are still applicable.1,000,000) correctly? Test with:
$transformer = app('numberToWords')->getNumberTransformer('hu');
$transformer->toWords(1000000); // Should output "egy millió"
50.99 → 5099) still requires manual handling.hu) now critical for your application? If so, validate output for edge cases (e.g., 0, -50, 1,234,567.89).NumberToWordsHungarianTest) to catch regressions?$this->assertEquals('ötven', app('numberToWords')->transformNumber('hu', 50));
^3.0.1 to avoid unintended updates?@numberToWords($amount, app()->getLocale()) // Automatically uses 'hu' if app locale is set to 'hu'
public function toArray(): array {
return [
'amount_words_hu' => app('numberToWords')->transformNumber('hu', $this->amount),
];
}
php artisan number-to-words:convert --locale=hu --input=orders.csv
laravel-dompdf or spatie/laravel-pdf to ensure Hungarian text renders correctly.laravel-lang/lang to ensure hu locale settings align.composer.json to ^3.0.1 and test Hungarian outputs:
composer require kwn/number-to-words:^3.0.1
0, 1, 100, 1,000,000).config/number-to-words.php (if using a custom config).function toCurrencyWordsHungarian(float $amount): string {
$cents = round($amount * 100);
return app('numberToWords')->transformNumber('hu', $cents) . " forint";
}
| Step | Priority | Dependencies |
|---|---|---|
Update composer.json to ^3.0.1 |
High | Composer |
| Test Hungarian outputs | High | Manual QA |
| Update Blade/API templates | Medium | Existing integrations |
| Add Hungarian to CI tests | Low | Test suite |
| Document Hungarian use cases | Low | Internal wiki |
^3.0.1 to avoid unintended updates:
"kwn/number-to-words": "^3.0.1"
hu.## Hungarian Support
- Fixed: Correct output for numbers (e.g., `50` → "ötven").
- Note: Currency requires manual scaling (e.g., `50.99` → `5099`).
try {
return $transformer->toWords($number);
} catch (\Exception $e) {
Log::warning("Hungarian number-to-words failed: {$e->getMessage()}");
return "Hiba: {$number}"; // Fallback with error message in Hungarian
}
Cache::remember("numberTransformer_hu", now()->addHours(1), fn() =>
app('numberToWords')->getNumberTransformer('hu')
);
| Scenario | Impact | Mitigation |
|---|---|---|
| Hungarian regression | Incorrect outputs (e.g., 50 → "öt") |
Fallback to raw number + warning |
| Large-number edge case | "egy millió" → incorrect output | Test with 1,000,000 in CI |
| Currency misalignment | 50.99 → wrong cents handling |
Manual scaling (unchanged) |
Locale conflict (e.g., hu_HU vs. hu) |
Inconsistent behavior | Standardize on hu in config |
NO_UPDATE_NEEDED would **not
How can I help you explore Laravel packages today?