christs_dev/money-to-words-converter

This package is abandoned and no longer maintained. The author suggests using the tnkemdilim/money-to-words-converter package instead.

A php library that converts any money value in digit in any language or numeric system to its words in any language

2.1.0 2021-06-21 17:41 UTC

README

Packagist Build Status PHP from Packagist Packagist

A php library that converts any money value in digit in any language or numeric system to its words in any language

Caveat

Currently, this library relies on stichoza/google-translate-php which could result in periodic 400 Bad Request as highlighted here and here.

If you care about reliability, kindly checkout a managed API service I run: Tuforty.

Installation

composer require tnkemdilim/money-to-words-converter
  • Or edit your project's composer.json to require tnkemdilim/money-to-words-converter and then run composer update.
"require": {
    "tnkemdilim/money-to-words-converter": "^2"
}

Example

For working example, checkout the Example folder.

Usage

Note: You should have composer's autoloader included require 'vendor/autoload.php'

Always include Converter namespace to your php file

Basic usage

use TNkemdilim\MoneyToWords\Converter;

// Nigerian currency : naira & kobo
$converter = new Converter("naira", "kobo");
echo ($converter->convert(374));
echo ($converter->convert(23.45));
echo ($converter->convert(748247284782));
echo ($converter->convert(748247284782.34));
echo ($converter->convert('34'));
echo ($converter->convert('2345.34'));
echo ($converter->convert('3453345'));

Other Languages

To convert money value to other languages, you'll need to import the Languages namespace

use TNkemdilim\MoneyToWords\Converter;
use TNkemdilim\MoneyToWords\Languages as Language;

$converter = new Converter("naira", "kobo", Language::FRENCH);

echo ($converter->convert(23.45));
echo ($converter->convert("748247284782"));

Convertion From Other Numeric System

Conversion from other numeric systems are supported in-built, and by default needs no extra configuration to convert into words.

Read more about Numeric systems.

// Chinese numeric system
$money = "八百七十二万七千八百二十四";

// Example 1
$converter = new Converter("yen", "sen");
echo ($converter->convert($money));

// Example 2: but convert money value to french
$frenchConverter = new Converter("yen", "sen", Language::FRENCH);
echo ($frenchConverter->convert("八百七十二万七千八百二十四"));

Change Currency

To change the currency of the money to convert

//  Dollars & Cents
$converter->setCurrency("dollar", "cents");
echo ($converter->convert(234.34)); // two hundred and thirty-four dollars, thirty-four cents only.

// Pounds & Pence
$converter->setCurrency("pounds", "pence");
echo ($converter->convert('23.3')); // twenty three pounds, 3 pence only.

Change Language Translation

Language for translation can be easily changed as follows. All available languages can be accessed via the TNkemdilim\MoneyToWords\Languages class.

See all available in Languages.

use TNkemdilim\MoneyToWords\Languages as Language;

$converter->setLanguage(Language::LATIN);
$converter->setLanguage(Language::SWAHILI);
$converter->setLanguage(Language::GREEK);

Supported Languages

For more conversion types

Language Name Code Language Name Code Language Name Code Language Name Code
Afrikaans af Irish ga Albanian sq Italian it
Arabic ar Japanese ja Azerbaijani az Kannada kn
Basque eu Korean ko Bengali bn Latin la
Belarusian be Latvian lv Bulgarian bg Lithuanian lt
Catalan ca Macedonian mk Chinese Simplified zh-CN Malay ms
Chinese Traditional zh-TW Maltese mt Croatian hr Norwegian no
Czech cs Persian fa Danish da Polish pl
Dutch nl Portuguese pt English en Romanian ro
Esperanto eo Russian ru Estonian et Serbian sr
Filipino tl Slovak sk Finnish fi Slovenian sl
French fr Spanish es Galician gl Swahili sw
Georgian ka Swedish sv German de Tamil ta
Greek el Telugu te Gujarati gu Thai th
Haitian Creole ht Turkish tr Hebrew iw Ukrainian uk
Hindi hi Urdu ur Hungarian hu Vietnamese vi
Icelandic is Welsh cy Indonesian id Yiddish yi

Contribution

  1. Fork it!
  2. Create your feature branch: git checkout -b feature-name
  3. Commit your changes: git commit -am 'Some commit message'
  4. Push to the branch: git push origin feature-name
  5. Submit a pull request 😉😉

License

MIT © Tochukwu Nkemdilim