khaled.alshamaa/ar-php
Ar-PHP is a PHP library for Arabic language processing: text shaping and normalization, transliteration, date/hijri handling, numbers-to-words, and other Arabic-specific utilities. Useful for Arabic web apps, reports, and localization.
composer require khaled.alshamaa/ar-php in your Laravel project. The package uses PSR-4 autoloading, so no extra setup is needed if you’re using Laravel’s default vendor/autoload.php.use ArPHP\I18N\Arabic;
$text = 'السَّلَامُ عَلَيْكُمْ';
$standardized = Arabic::standardize($text); // Normalizes harakat, lam-alef ligatures, etc.
Arabic::standardize(), Arabic::strToTime(), or Arabic::gender()—these are lightweight and commonly needed for basic localization.// App\Providers\AppServiceProvider
public function register() {
$this->app->singleton('arabic', function() {
return new Arabic();
});
}
Then inject Arabic or resolve via app('arabic').standardize(), stripTashkeel(), and transliterate() to normalize user queries and DB content before full-text search (MySQL/PostgreSQL).standardize() in model mutators:
public function setTitleAttribute($value) {
$this->attributes['title'] = Arabic::standardize($value);
}
mktime(), jdate(), or salat() in scheduled tasks (e.g., sending prayer-time reminders).glyphs(), keyswap(), or sentiment() in Blade components (e.g., {!! Arabic::glyphs($text) !!} for browser-safe rendering).stripTashkeel() removes diacritics but does not normalize alif forms (أ, إ, آ → ا). Always run standardize() first if comparing strings.<meta charset="UTF-8">) and ensure DB tables use utf8mb4. Ar-PHP assumes UTF-8 input; mix encoding and you’ll get mojibb-like artifacts.sentiment(), similarity(), and summarize() are computationally heavy. Cache results or batch-process in queues (e.g., Laravel Horizon).detectDialect() relies on pattern matching; it’s ~80% accurate on average. Don’t use it for critical decisions (e.g., legal docs).I18N/Arabic/SpellChecker.php, etc.). Override or extend via inheritance or composition (e.g., add domain-specificspell-check rules).Transliteration class has better examples online (see en_transliteration.php in GitHub examples). Check the demo list for usage clues when PHPDoc is sparse.How can I help you explore Laravel packages today?