codemarkt/laravel-number-to-words
Composer 安装命令:
composer require codemarkt/laravel-number-to-words
包简介
Multi-language and multi-currency number to words converter for Laravel
关键字:
README 文档
README
Multi-language and multi-currency number to words converter for Laravel.
Features
- Convert numbers to words in multiple languages (Turkish, English)
- Convert currency amounts to words with proper formatting
- Smart pluralization support (e.g., "1 dollar" vs "2 dollars")
- Flexible input parsing (handles various number formats)
- Customizable output (uppercase, lowercase, custom separators)
- Fail-safe (never throws exceptions)
- Easy to extend with new languages and currencies
Installation
composer require codemarkt/laravel-number-to-words
Configuration
Publish the configuration file:
php artisan vendor:publish --tag=number-to-words-config
Publish the language files (optional):
php artisan vendor:publish --tag=number-to-words-lang
Configuration options in config/number-to-words.php:
return [ 'locale' => 'tr', 'fallback_locale' => 'en', 'case' => 'lowercase', 'separator' => ' ', ];
Usage
Recommended: Using Helper Functions (Shorter Syntax)
// Convert numbers to words number_to_words(154); // Uses default locale from config number_to_words(154, 'tr'); // "yüz elli dört" number_to_words(154, 'en'); // "one hundred fifty four" // Convert currency amounts number_to_currency_words(8097.21, 'TRY', 'tr'); // "sekiz bin doksan yedi türk lirası yirmi bir kuruş" number_to_currency_words(150.50, 'USD', 'en'); // "one hundred fifty us dollar fifty cent" // With custom formatting number_to_words(123, 'tr', 'uppercase', '-'); // "YÜZ-YİRMİ-ÜÇ"
Using Facade (Alternative)
use CodeMarkt\NumberToWords\Facades\NumberToWords; // Or use the global alias (automatically registered) use NumberToWords; NumberToWords::toWords(154, 'tr'); // "yüz elli dört" NumberToWords::toCurrency(8097.21, 'TRY', 'tr'); // "sekiz bin doksan yedi türk lirası yirmi bir kuruş"
Using Service Container
$service = app(\CodeMarkt\NumberToWords\NumberToWordsService::class); $service->toWords(154, 'tr');
Input Formats
The package handles various number formats automatically:
NumberToWords::toWords('8.097,21'); // Turkish format → 8097.21 NumberToWords::toWords('1,200.56'); // English format → 1200.56 NumberToWords::toWords('18 500,90'); // With spaces → 18500.90 NumberToWords::toWords(1200.0); // Float NumberToWords::toWords(1200); // Integer
Supported Languages
- Turkish (tr)
- English (en)
Supported Currencies
- TRY (Turkish Lira)
- USD (US Dollar)
- EUR (Euro)
- GBP (British Pound)
Adding Custom Languages and Currencies
Adding a New Currency
Simply add the currency to your language files. The package supports both simple strings and pluralization:
Simple format (backward compatible):
'currencies' => [ 'JPY' => [ 'major' => 'Japanese yen', 'minor' => '', // Leave empty if no minor unit ], ],
With pluralization (recommended for proper grammar):
'currencies' => [ 'USD' => [ 'major' => [ 'singular' => 'US dollar', 'plural' => 'US dollars', ], 'minor' => [ 'singular' => 'cent', 'plural' => 'cents', ], ], ],
The package automatically uses the correct form based on the amount:
1.50 USD→ "one US dollar fifty cents"2.00 USD→ "two US dollars"
Creating a New Language File
Create a new language file in resources/lang/vendor/number-to-words/{locale}/number.php:
return [ 'digits' => [ '0' => 'zero', '1' => 'one', // ... ], 'tens' => [ '10' => 'ten', '20' => 'twenty', // ... ], 'hundred' => 'hundred', 'exponents' => [ 0 => '', 1 => 'thousand', 2 => 'million', // ... ], 'currencies' => [ 'USD' => [ 'major' => 'dollar', 'minor' => 'cent', ], // ... ], ];
Testing
composer test
License
The MIT License (MIT). Please see License File for more information.
codemarkt/laravel-number-to-words 适用场景与选型建议
codemarkt/laravel-number-to-words 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「currency」 「converter」 「laravel」 「english」 「Turkish」 「pluralization」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 codemarkt/laravel-number-to-words 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 codemarkt/laravel-number-to-words 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 codemarkt/laravel-number-to-words 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Tools to convert between .NET and PHP date formats
Encode integer IDs using a preset or customized symbol set
Fixer.io data provider for Peso
TCMB Currenct Converter
Immutable PHP currency converter that's data-agnostic.
Alfabank REST API integration
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-18