azmolla/spell-money-multilang 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

azmolla/spell-money-multilang

Composer 安装命令:

composer require azmolla/spell-money-multilang

包简介

Convert numbers to words for money in Bangla, English, Hindi, Chinese, Thai, and Arabic. Extensible to any language.

README 文档

README

Latest Stable Version License PHP Version Require Tests

Convert numbers into words for money amounts across multiple languages. Currently supports Bangla, English, Hindi, Chinese, Thai, and Arabic, with proper numeral recognition. Designed to be easily extendable so you can add new languages.

Installation

Install via Composer:

composer require azmolla/spell-money-multilang

Usage

use AzMolla\SpellMoney\SpellMoney;
use AzMolla\SpellMoney\Languages\Bangla;
use AzMolla\SpellMoney\Languages\English;
use AzMolla\SpellMoney\Languages\Hindi;
use AzMolla\SpellMoney\Languages\Chinese;
use AzMolla\SpellMoney\Languages\Thai;
use AzMolla\SpellMoney\Languages\Arabic;

// Bangla (default)
$spell = new SpellMoney(new Bangla());
echo $spell->spell("১২৩৪৫.৫০");
// বারো হাজার তিন শত পঁইতাল্লিশ টাকা পঞ্চাশ পয়সা

// English
$spell = new SpellMoney(new English());
echo $spell->spell(12345.50);
// twelve thousand three hundred forty five taka fifty paisa

// Hindi
$spell = new SpellMoney(new Hindi());
echo $spell->spell("१२३४५.५०");
// बारह हज़ार तीन सौ पैंतालीस रुपये पचास पैसा

// Chinese
$spell = new SpellMoney(new Chinese());
echo $spell->spell("12345.50");
// 一万二千三百四十五 元 五十 分

// Thai
$spell = new SpellMoney(new Thai());
echo $spell->spell("๑๒๓๔๕.๕๐");
// หนึ่งหมื่นสองพันสามร้อยสี่สิบห้า บาท ห้าสิบ สตางค์

// Arabic
$spell = new SpellMoney(new Arabic());
echo $spell->spell("١٢٣٤٥.٥٠");
// اثنا عشر ألف ثلاثمائة خمسة وأربعون جنيه خمسون قرش

or

use AzMolla\SpellMoney\SpellMoney;
use AzMolla\SpellMoney\Languages\Bangla;

SpellMoney::convert("12345.50", new Bangla());

Supported Numeral Systems

Language Digits Recognized Example Input Example Output
Bangla ০–৯ ১২৩ এক শত তেইশ টাকা
Hindi ०–९ १२३ एक सौ तेईस रुपये
Arabic ٠–٩ ١٢٣ مائة و ثلاثة و عشرون جنيه
Thai ๐–๙ ๑๒๓ หนึ่งร้อยยี่สิบสาม บาท
Chinese 0–9 (fullwidth), 0–9 12৩ or 123 一百二十三 元
English 0–9 123 one hundred twenty three taka

✅ Both local numerals and standard 0–9 digits are supported. ✅ Each language normalizes its own digit system internally.

Features

  • Convert numbers to money words in multiple languages.

  • Works with both local numerals and standard digits.

  • Supports integer + decimal amounts.

  • Currency and sub-currency names are language-specific:

    • Bangla → টাকা / পয়সা
    • Hindi → रुपये / पैसा
    • Arabic → جنيه / قرش
    • Chinese → 元 / 分
    • Thai → บาท / สตางค์
    • English → taka / paisa
  • Easily extendable — just add a new Language class.

Adding a New Language

  1. Create a class in src/Languages/, for example French.php.
  2. Implement the LanguageInterface.
<?php
namespace AzMolla\SpellMoney\Languages;

use AzMolla\SpellMoney\Contracts\LanguageInterface;

class French implements LanguageInterface
{
    public function normalizeNumber(string $number): string
    {
        return $number; // French uses Arabic numerals
    }

    public function toWords(int $num): string
    {
        // Implement French spelling here
        return "cent vingt-trois"; // 123
    }

    public function getCurrency(): string { return "euro"; }
    public function getSubCurrency(): string { return "centime"; }
}
  1. Use it in code:
$spell = new SpellMoney(new French());
echo $spell->spell(123.45);
// cent vingt-trois euro quarante-cinq centimes

Demo

Clone the repo and run the demo:

php examples/demo.php

Example output:

[Bangla] বারো হাজার তিন শত পঁইতাল্লিশ টাকা পঞ্চাশ পয়সা
[English] twelve thousand three hundred forty five taka fifty paisa
[Hindi] बारह हज़ार तीन सौ पैंतालीस रुपये पचास पैसा
[Chinese] 一万二千三百四十五 元 五十 分
[Thai] หนึ่งหมื่นสองพันสามร้อยสี่สิบห้า บาท ห้าสิบ สตางค์
[Arabic] اثنا عشر ألف ثلاثمائة خمسة وأربعون جنيه خمسون قرش

Running Tests

Install dependencies and run PHPUnit:

composer install
vendor/bin/phpunit tests

In VS Code, you can also run tests from the Testing tab if you have the PHPUnit Test Explorer extension installed.

GitHub Actions CI

This package includes CI to run tests on push and pull requests. See .github/workflows/tests.yml.

Roadmap

  • Expand irregular forms in Bangla/Hindi (একুশ, बाईस, etc.).
  • Add more languages (French, Japanese, German, etc.).
  • Accept community contributions 🎉.

License

MIT © Abiruzzaman Molla

azmolla/spell-money-multilang 适用场景与选型建议

azmolla/spell-money-multilang 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 3, 最近一次更新时间为 2025 年 08 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「library」 「money」 「multilanguage」 「numbers」 「english」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 azmolla/spell-money-multilang 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 azmolla/spell-money-multilang 我们能提供哪些服务?
定制开发 / 二次开发

基于 azmolla/spell-money-multilang 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 31
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-26