Skip to content

Commit

Permalink
Merge pull request #4 from rmunate/3.X
Browse files Browse the repository at this point in the history
3.x
  • Loading branch information
rmunate authored Aug 13, 2023
2 parents cc3dd31 + bc04423 commit f5cfc8e
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 53 deletions.
95 changes: 67 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Convert Numbers to Words in Laravel

Easily convert numbers to words in Laravel using this library, which supports the native PHP INTL extension to perform the conversion seamlessly. This library allows you to convert numbers to words in multiple languages and also get the value in currency format based on the selected language. Supported languages include English, Spanish, Portuguese, French, Italian, Romanian, and Persian.
Easily convert numbers to words in Laravel using this library, which leverages the native `PHP INTL` extension to perform conversion effortlessly. With this library, you can convert numbers to words in various languages and also obtain the value in currency format according to the selected language. Supported languages include English, Spanish, Portuguese, French, Italian, Romanian, and with the contribution of [Siros Fakhri](https://github.com/sirosfakhri), Persian (Farsi) support has been added.

⚙️ This library is compatible with Laravel versions 8.0 and higher ⚙️

Expand All @@ -11,64 +11,103 @@ Easily convert numbers to words in Laravel using this library, which supports th
![SpellNumbers](https://github.com/rmunate/SpellNumber/assets/91748598/f2aea68b-fc9f-46be-ae54-a4955f0ce7a2)

## Table of Contents

- [Installation](#installation)
- [Usage](#usage)
- [Creator](#creator)
- [Contributors](#contributors)
- [License](#license)

## Installation

To install the dependency via Composer, execute the following command:

```shell
composer require rmunate/spell-number
```

Make sure that the `intl` extension is enabled and loaded in your environment.
It's important to ensure that the `intl` extension is enabled and loaded in the environment.

## Usage

After installing the dependency in your project, you can start using it with the following examples:

#### Knowing Supported Regional Configurations

To obtain the current list of languages with support, execute the following command:

```php
// GET AVAILABLE LOCALES
SpellNumber::getAllLocales();
// array:6 [▼ //
// 0 => "en"
// 1 => "es"
// 2 => "pt"
// 3 => "fr"
// 4 => "it"
// 5 => "ro"
// 6 => "fa"
// array:7 [▼
// 0 => "en" (English)
// 1 => "es" (Spanish)
// 2 => "pt" (Portuguese)
// 3 => "fr" (French)
// 4 => "it" (Italian)
// 5 => "ro" (Romanian)
// 6 => "fa" (Farsi)
// ]
```

#### Convert Integers to Words

You can easily convert numbers to words by defining the regional configuration to apply. If you don't define a regional configuration, "en" (English) will be applied by default.

```php
SpellNumber::value(100)->locale('es')->toLetters();
// "Cien"

SpellNumber::value(100)->locale('fa')->toLetters();
// "صد"

// CONVERT INTEGER TO WORDS
SpellNumber::value(100)->locale('en')->toLetters();
// "One Hundred"
SpellNumber::value(12300000)->locale('en')->toLetters();
// "Twelve Million Three Hundred Thousand"
```

// CONVERT FLOAT TO WORDS
SpellNumber::value(123456789.12)->locale('en')->toLetters();
// "One Hundred Twenty-Three Million Four Hundred Fifty-Six Thousand Seven Hundred Eighty-Nine Point Twelve"
#### Convert Floating-Point Numbers

// CONVERT INTEGER TO CURRENCY TEXT FORMAT
SpellNumber::value(100)->locale('en')->currency('dollars')->toMoney();
// "One Hundred Dollars"
SpellNumber::value(100.12)->locale('en')->currency('Dollars')->fraction('cents')->toMoney();
// "One Hundred Dollars and Twelve Cents"
If needed, you can pass a floating-point number as an argument to convert it to words.

// OTHER STARTING METHODS
```php
SpellNumber::value(123456789.12)->locale('es')->toLetters();
// "Ciento Veintitrés Millones Cuatrocientos Cincuenta Y Seis Mil Setecientos Ochenta Y Nueve Con Doce"
```

// Integer, this method strictly requires an integer value as an argument.
SpellNumber::integer(100)->locale('en')->toLetters();
#### Convert to Currency Format

// Floats, this method strictly requires a string value as an argument.
SpellNumber::float('12345.23')->locale('en')->toLetters();
This method can be useful for invoices, receipts, and similar scenarios. Obtain the supplied value in currency format.

```php
SpellNumber::value(100)->locale('es')->currency('pesos')->toMoney();
// "Cien Pesos"

SpellNumber::value(100.12)->locale('es')->currency('Pesos')->fraction('centavos')->toMoney();
// "Cien Pesos Con Doce Centavos"

SpellNumber::value(100)->locale('fa')->currency('تومان')->toMoney();
// "صد تومان"
```

#### Other Initializer Methods

To support version 1.X, the following initializer methods are maintained.

```php
// Integer, this method strictly requires an integer value to be sent as an argument.
SpellNumber::integer(100)->locale('es')->toLetters();

// Floating-point numbers, this method strictly requires a string value as an argument.
SpellNumber::float('12345.23')->locale('es')->toLetters();
```

## Creator

- 🇨🇴 Raúl Mauricio Uñate Castro
- Email: [email protected]

## Contributors
[Siros Fakhri](https://github.com/sirosfakhri) (Farsi Language)

## License
This project is under the [MIT License](https://choosealicense.com/licenses/mit/).

This project is licensed under the [MIT License](https://choosealicense.com/licenses/mit/).
72 changes: 56 additions & 16 deletions README_SPANISH.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Convertir de números a Letras en Laravel
# Convertir Números a Letras en Laravel

Convierta fácilmente números a letras en Laravel utilizando esta biblioteca, que admite la extensión nativa PHP INTL para realizar la conversión de manera sencilla. Con esta librería, puede convertir números a letras en varios idiomas y también obtener el valor en formato de moneda según el idioma seleccionado. Los idiomas con soporte incluyen inglés, español, portugués, francés, italiano y rumano.
Convierte fácilmente números a letras en Laravel utilizando esta biblioteca, que emplea la extensión nativa `PHP INTL` para realizar la conversión de manera sencilla. Con esta librería, puedes convertir números a letras en varios idiomas y también obtener el valor en formato de moneda según el idioma seleccionado. Los idiomas con soporte incluyen inglés, español, portugués, francés, italiano, rumano y gracias a la colaboración de [Siros Fakhri](https://github.com/sirosfakhri), también se ha agregado soporte para persa (Farsi).

⚙️ Esta librería es compatible con versiones de Laravel 8.0 y superiores ⚙️

Expand All @@ -11,12 +11,15 @@ Convierta fácilmente números a letras en Laravel utilizando esta biblioteca, q
![SpellNumbers](https://github.com/rmunate/SpellNumber/assets/91748598/f2aea68b-fc9f-46be-ae54-a4955f0ce7a2)

## Tabla de Contenidos

- [Instalación](#instalación)
- [Uso](#uso)
- [Creador](#creador)
- [Contribuidores](#contribuidores)
- [Licencia](#licencia)

## Instalación

Para instalar la dependencia a través de Composer, ejecuta el siguiente comando:

```shell
Expand All @@ -26,38 +29,70 @@ composer require rmunate/spell-number
Es importante asegurarse de que la extensión `intl` esté habilitada y cargada en el entorno.

## Uso

Después de instalar la dependencia en tu proyecto, puedes empezar a usarla con los siguientes ejemplos:

#### Conocer las Configuraciones Regionales con Soporte

Para obtener el listado actual de idiomas con soporte, ejecuta el siguiente comando:

```php
// OBTENER LOS IDIOMAS DISPONIBLES
SpellNumber::getAllLocales();
// array:6 [▼ //
// 0 => "en"
// 1 => "es"
// 2 => "pt"
// 3 => "fr"
// 4 => "it"
// 5 => "ro"
// array:7 [▼
// 0 => "en" (Inglés)
// 1 => "es" (Español)
// 2 => "pt" (Portugués)
// 3 => "fr" (Francés)
// 4 => "it" (Italiano)
// 5 => "ro" (Rumano)
// 6 => "fa" (Farsi)
// ]
```

#### Convertir Números Enteros a Letras

// CONVERTIR ENTERO A LETRAS
Puedes convertir fácilmente números a letras definiendo la configuración regional a aplicar. Si no defines la configuración regional, por defecto se aplicará "en" (Inglés).

```php
SpellNumber::value(100)->locale('es')->toLetters();
// "Cien"
SpellNumber::value(12300000)->locale('es')->toLetters();
// "Doce Millones Trescientos Mil"

// CONVERTIR FLOAT A LETRAS
SpellNumber::value(100)->locale('fa')->toLetters();
// "صد"

SpellNumber::value(100)->locale('en')->toLetters();
// "One Hundred"
```

#### Convertir Números de Coma Flotante

Si lo necesitas, puedes enviar un número de coma flotante como argumento para convertirlo a letras.

```php
SpellNumber::value(123456789.12)->locale('es')->toLetters();
// "Ciento Veintitrés Millones Cuatrocientos Cincuenta Y Seis Mil Setecientos Ochenta Y Nueve Con Doce"
```

#### Convertir a Formato Moneda

Este método puede ser útil para facturas, remisiones y similares. Obtén el valor suministrado en formato moneda.

// CONVERTIR ENTERO A FORMATO TEXTO MONEDA
```php
SpellNumber::value(100)->locale('es')->currency('pesos')->toMoney();
// "Cien Pesos"

SpellNumber::value(100.12)->locale('es')->currency('Pesos')->fraction('centavos')->toMoney();
// "Cien Pesos Con Doce Centavos"

// OTROS MÉTODOS DE INICIO
SpellNumber::value(100)->locale('fa')->currency('تومان')->toMoney();
// "صد تومان"
```

#### Otros Métodos Inicializadores

Para dar soporte a la versión 1.X, se mantienen los siguientes inicializadores.

```php
// Entero, este método requiere de forma estricta que se envíe un valor entero como argumento.
SpellNumber::integer(100)->locale('es')->toLetters();

Expand All @@ -66,8 +101,13 @@ SpellNumber::float('12345.23')->locale('es')->toLetters();
```

## Creador

- 🇨🇴 Raúl Mauricio Uñate Castro
- Correo electrónico: [email protected]

## Contribuidores
[Siros Fakhri](https://github.com/sirosfakhri) (Idioma Farsi)

## Licencia

Este proyecto se encuentra bajo la [Licencia MIT](https://choosealicense.com/licenses/mit/).
18 changes: 9 additions & 9 deletions src/Langs/Langs.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ final class Langs
* @var array
*/
public const LOCALES_CONNECTORS = [
'en' => 'and', // English from the United States: "and"
'es' => 'con', // Spanish from Spain: "con"
'pt' => 'com', // Portuguese from Portugal: "com"
'fr' => 'et', // French from France: "et"
'it' => 'con', // Italian from Italy: "con"
'ro' => 'cu', // Romanian from Romania: "cu"
'en' => 'and', // English from the United States: "and"
'es' => 'con', // Spanish from Spain: "con"
'pt' => 'com', // Portuguese from Portugal: "com"
'fr' => 'et', // French from France: "et"
'it' => 'con', // Italian from Italy: "con"
'ro' => 'cu', // Romanian from Romania: "cu"
'fa' => 'ممیز', // Farsi from Iran: "ممیز"
];

Expand All @@ -45,10 +45,10 @@ final class Langs
'en' => 'of', // English from the United States: "of"
'es' => 'de', // Spanish from Spain: "de"
'pt' => 'de', // Portuguese from Portugal: "de"
'fr' => 'de', // French from France: "de"
'fr' => 'de', // French from France: "de"
'it' => 'di', // Italian from Italy: "di"
'ro' => 'de', // Romanian from Romania: "de"
'fa' => 'از', // Farsi from Iran: "از"
'ro' => 'de', // Romanian from Romania: "de"
'fa' => 'از', // Farsi from Iran: "از"
];

/**
Expand Down

0 comments on commit f5cfc8e

Please sign in to comment.