yafet/amharic-transliteration
最新稳定版本:v1.0.2
Composer 安装命令:
composer require yafet/amharic-transliteration
包简介
A Laravel package for Amharic to English and English to Amharic transliteration.
README 文档
README
A Laravel package for dual-way Amharic to English transliteration. Effortlessly convert Amharic script to English phonetics and back.
Features
- Amharic to English: Converts Amharic characters to English with smart suffix handling (removes 'i' at word endings).
- English to Amharic: Reverse conversion using the longest-match algorithm for complex phonetics (e.g.,
she,gn´e). - Laravel Integration: Facades, Traits, and Service Providers included.
- Customizable: Publish and modify the letter mapping as needed.
Installation
You can install the package via composer:
composer require yafet/amharic-transliteration
For local development or if the package is in a private folder:
"repositories": [ { "type": "path", "url": "./packages/amharic-transliteration" } ], "require": { "yafet/amharic-transliteration": "*" }
Usage
1. Using the Facade
The simplest way to use the package is via the Amharic facade.
use Yafet\AmharicTransliteration\Facades\Amharic; // Amharic to English $english = Amharic::transliterate("ላም"); // Result: "lam" // English to Amharic $amharic = Amharic::reverseTransliterate("lam"); // Result: "ላም"
2. Using the Trait in Models
Add the Transliteratable trait to your Eloquent models to easily convert attributes.
namespace App\Models; use Illuminate\Database\Eloquent\Model; use Yafet\AmharicTransliteration\Traits\Transliteratable; class Post extends Model { use Transliteratable; protected $fillable = ['title_am']; // Get English transliteration of the title public function getTitleEnAttribute() { return $this->transliterateAttribute('title_am'); } }
3. Manual Service Injection
use Yafet\AmharicTransliteration\TransliterationService; public function __construct(TransliterationService $service) { $this->service = $service; } public function convert() { return $this->service->transliterate("ሀሎ"); }
Configuration
If you want to modify the character mapping, you can publish the resources:
php artisan vendor:publish --tag="amharic-transliteration-resources"
The mapping will be available at resources/json/amharicLetters.json.
Development & Testing
To run tests, ensure you have dev dependencies installed:
composer install vendor/bin/phpunit
Running Tests via PHP script
A lightweight test script is provided in the root:
php test.php
Changelog
v1.0.0
- Initial release.
- Support for Amharic to English transliteration.
- Support for English to Amharic (reverse) transliteration.
- Laravel Facade and Trait support.
- PHPUnit test suite.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-05-11