定制 omar-haris/arabic-name-transliterator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

omar-haris/arabic-name-transliterator

Composer 安装命令:

composer require omar-haris/arabic-name-transliterator

包简介

A PHP library to transliterate Arabic names to English names can handle Arabic names with diacritics and special characters.

README 文档

README

A powerful PHP library for transliterating Arabic names to English with high accuracy. Perfect for ID systems, passports, and any application needing reliable Arabic-to-English name conversion.

Latest Version on Packagist Tests PHP Version License: MIT Total Downloads

Why This Library?

Transliterating Arabic names to English is challenging due to multiple correct spellings and regional variations. This library solves that problem with:

  • Accurate transliteration that follows standard conventions
  • Support for names with diacritics (harakat)
  • Regional variations (currently Iraqi mapping, with extensibility for other regions)
  • Smart word-level and character-level mapping
  • Full customization options to meet your specific needs

Key Features

  • Dictionary-based approach for common names and words
  • Fallback letter-by-letter mapping for names not in the dictionary
  • Customizable regional mappings for different Arabic dialects and standards
  • Clean handling of diacritics (harakat) and special characters
  • Well-documented code with comprehensive test coverage
  • Zero external dependencies besides PHP's mbstring

Installation

Simply run:

composer require omar-haris/arabic-name-transliterator

Basic Usage

use ArabicNameTransliterator\Transliterator;
use ArabicNameTransliterator\Mapping\IraqMapping;

// Create a transliterator with Iraqi name mapping
$transliterator = new Transliterator(new IraqMapping());

// Transliterate names
echo $transliterator->transliterate('محمد');                // "Muhammad"
echo $transliterator->transliterate('عبد الرحمن');          // "Abd Al-Rahman"
echo $transliterator->transliterate('فاطمة الزهراء');       // "Fatimah Al-Zahraa"

// Works with diacritics
echo $transliterator->transliterate('مُحَمَّد');            // "Muhammad"

// Disable capitalization
echo $transliterator->transliterate('محمد علي', false);     // "muhammad ali"

Advanced Usage

Creating Custom Mappings

You can create your own mappings by extending BaseMapping:

use ArabicNameTransliterator\Mapping\BaseMapping;

class EgyptianMapping extends BaseMapping
{
    public function getFullWordMap(): array
    {
        return [
            'محمد' => 'Mohamed',  // Egyptian spelling (vs. Iraqi "Muhammad")
            'عبد الرحمن' => 'Abdelrahman', // Different format
            // Add more mappings...
        ];
    }
    
    public function getLetterMap(): array
    {
        return [
            'ج' => 'g',  // In Egyptian dialect, ج is pronounced as "g" not "j"
            // Define the rest of your letter map...
        ];
    }
}

$egyptianTransliterator = new Transliterator(new EgyptianMapping());

Extending Existing Mappings

You can also extend an existing mapping:

use ArabicNameTransliterator\Mapping\IraqMapping;

class CustomIraqMapping extends IraqMapping
{
    public function getFullWordMap(): array
    {
        $originalMap = parent::getFullWordMap();
        
        // Add or override specific entries
        $customEntries = [
            'محمد' => 'Mohammed', // Override the default 'Muhammad'
            'عبد العزيز' => 'Abdul Aziz', // New entry
        ];
        
        return array_merge($originalMap, $customEntries);
    }
}

How It Works

The transliteration process follows these steps:

  1. The input Arabic text is split into words
  2. Each word is checked against the full-word dictionary
    • If found, the predefined transliteration is used
    • If not found, the word is transliterated letter by letter
  3. The transliterated words are joined with spaces
  4. By default, each word is capitalized (can be disabled)

Available Mappings

Currently, the library includes:

  • IraqMapping: Suitable for Iraqi Arabic names, following common standards for official documents

More regional mappings will be added in future releases. Contributions are welcome!

Requirements

  • PHP 8.3+
  • mbstring extension

License

MIT License. See the LICENSE file.

Credits

omar-haris/arabic-name-transliterator 适用场景与选型建议

omar-haris/arabic-name-transliterator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 299 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 04 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 omar-haris/arabic-name-transliterator 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-28