承接 devhamidshahbazi/number-normalizer 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

devhamidshahbazi/number-normalizer

Composer 安装命令:

composer require devhamidshahbazi/number-normalizer

包简介

Laravel package to automatically normalize any non-English digits (Persian, Arabic, Urdu, etc.) to English numbers in all requests

README 文档

README

Latest Version on Packagist Total Downloads License

Laravel package to automatically normalize any non-English digits to English numbers in all requests.

✨ Features

  • 🌍 10 Languages Supported - Persian, Arabic, Urdu, Hindi, Bengali, Gujarati, Thai, Khmer, Lao, Myanmar
  • 🚀 Auto Middleware - Automatically normalizes all incoming requests
  • ⚙️ Fully Configurable - Add custom languages, exclude routes, choose language combinations
  • 🔌 Extensible - Easy to add new languages via config or code
  • 🎯 Zero Configuration - Works out of the box with Persian and Arabic

📦 Installation

composer require devhamidshahbazi/number-normalizer

Publish the config file:

php artisan vendor:publish --tag=number-normalizer-config

🌍 Supported Languages

Languages with Custom Digits (10 Languages)

# Language Digits Example
1 Persian ۰۱۲۳۴۵۶۷۸۹ ۱۲۳123
2 Arabic ٠١٢٣٤٥٦٧٨٩ ١٢٣123
3 Urdu ۰۱۲۳۴۵۶۷۸۹ ۱۲۳123
4 Hindi ०१२३४५६७८९ १२३123
5 Bengali ০১২৩৪৫৬৭৮৯ ১২৩123
6 Gujarati ૦૧૨૩૪૫૬૭૮૯ ૧૨૩123
7 Thai ๐๑๒๓๔๕๖๗๘๙ ๑๒๓123
8 Khmer ០១២៣៤៥៦៧៨៩ ១២៣123
9 Lao ໐໑໒໓໔໕໖໗໘໙ ໑໒໓123
10 Myanmar ၀၁၂၃၄၅၆၇၈၉ ၁၂၃123

⚙️ Configuration

File: config/number-normalizer.php

// Active languages (merged and applied together)
'combined_languages' => [
    'persian',
    'arabic',
    'urdu',
    'hindi',
    'bengali',
    'gujarati',
    'thai',
    'khmer',
    'lao',
    'myanmar',
],

// Built-in mappings (complete for all 10 languages)
'mappings' => [
    'persian' => ['۰' => '0', '۱' => '1', '۲' => '2', /* ... */],
    'arabic'  => ['٠' => '0', '١' => '1', '٢' => '2', /* ... */],
    'urdu'    => ['۰' => '0', '۱' => '1', '۲' => '2', /* ... */],
    'hindi'   => ['' => '0', '' => '1', '' => '2', /* ... */],
    'bengali' => ['' => '0', '' => '1', '' => '2', /* ... */],
    'gujarati'=> ['' => '0', '' => '1', '' => '2', /* ... */],
    'thai'    => ['' => '0', '' => '1', '' => '2', /* ... */],
    'khmer'   => ['' => '0', '' => '1', '' => '2', /* ... */],
    'lao'     => ['' => '0', '' => '1', '' => '2', /* ... */],
    'myanmar' => ['' => '0', '' => '1', '' => '2', /* ... */],
],

// Custom languages (add your own)
'custom_mappings' => [
    // 'tamil' => ['௦' => '0', '௧' => '1', /* ... */],
],

// Excluded routes (not normalized)
'except' => [
    'api/webhook',
    'admin/*',
],

🚀 Adding a New Language

To add a new language:

  1. Define the mapping in custom_mappings:
'custom_mappings' => [
    'tamil' => [
        '' => '0', '' => '1', '' => '2', '' => '3',
        '' => '4', '' => '5', '' => '6', '' => '7',
        '' => '8', '' => '9',
    ],
],
  1. Add the language name to combined_languages:
'combined_languages' => [
    'persian', 'arabic', 'tamil', // Add your new language
],

🛠️ Middleware

By default, middleware is automatically added to all requests (auto_middleware => true).

To disable auto-registration and register manually:

// config/number-normalizer.php
'auto_middleware' => false,

Then in app/Http/Kernel.php:

protected $middleware = [
    // ...
    \NumberNormalizer\Http\Middleware\NormalizeNumbers::class,
];

Or apply only to specific routes:

Route::post('/register', ...)->middleware('normalize.numbers');

💻 Manual Usage

use NumberNormalizer\Facades\NumberNormalizer;

// Convert all supported languages
NumberNormalizer::toEnglish('قیمت: ۱۲۳۴ و ๑๒๓'); // قیمت: 1234 و 123

// Specific languages only
NumberNormalizer::toEnglish('۱۲۳ و ١٢٣', ['persian', 'arabic']);

// Custom mapping
NumberNormalizer::withMapping('۱۲۳', ['۱' => '1', '۲' => '2', '۳' => '3']);

🎯 Use Cases

  • 🌐 Multi-language applications - Normalize numbers from users worldwide
  • 📱 International forms - Phone numbers, national IDs, amounts
  • 💰 E-commerce - Currency amounts from different regions
  • 🏦 Financial systems - Standardize numerical inputs
  • 📊 Data processing - Clean and normalize data from various sources

📊 Language Coverage by Region

Region Languages
Middle East Persian, Arabic, Urdu
South Asia Hindi, Bengali, Gujarati
Southeast Asia Thai, Khmer, Lao, Myanmar
Europe Spanish

📝 License

The MIT License (MIT). Please see License File for more information.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

⭐ Support

If you find this package helpful, please give it a ⭐ on GitHub!

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-28