Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Ar Php Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install via Composer: Run 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.
  2. First Use Case: Standardize Arabic text input (e.g., for search indexing or DB storage).
    use ArPHP\I18N\Arabic;
    
    $text = 'السَّلَامُ عَلَيْكُمْ';
    $standardized = Arabic::standardize($text); // Normalizes harakat, lam-alef ligatures, etc.
    
  3. Explore Core Modules: Start with Arabic::standardize(), Arabic::strToTime(), or Arabic::gender()—these are lightweight and commonly needed for basic localization.

Implementation Patterns

  • Laravel Integration: Create service bindings (e.g., in a service provider) or use facades:
    // App\Providers\AppServiceProvider
    public function register() {
        $this->app->singleton('arabic', function() {
            return new Arabic();
        });
    }
    
    Then inject Arabic or resolve via app('arabic').
  • Text Preprocessing for Search: Combine standardize(), stripTashkeel(), and transliterate() to normalize user queries and DB content before full-text search (MySQL/PostgreSQL).
  • CRUD Automation: Hook standardize() in model mutators:
    public function setTitleAttribute($value) {
        $this->attributes['title'] = Arabic::standardize($value);
    }
    
  • Background Jobs: Use mktime(), jdate(), or salat() in scheduled tasks (e.g., sending prayer-time reminders).
  • UI Helpers: Wrap glyphs(), keyswap(), or sentiment() in Blade components (e.g., {!! Arabic::glyphs($text) !!} for browser-safe rendering).

Gotchas and Tips

  • No Harakat ≠ Zero-Diff: stripTashkeel() removes diacritics but does not normalize alif forms (أ, إ, آا). Always run standardize() first if comparing strings.
  • Encoding Matters: Force UTF-8 in HTML (<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.
  • Performance with Large Texts: sentiment(), similarity(), and summarize() are computationally heavy. Cache results or batch-process in queues (e.g., Laravel Horizon).
  • Dialect Detection is Heuristic: detectDialect() relies on pattern matching; it’s ~80% accurate on average. Don’t use it for critical decisions (e.g., legal docs).
  • Extensibility: Core logic is decoupled into modules (I18N/Arabic/SpellChecker.php, etc.). Override or extend via inheritance or composition (e.g., add domain-specificspell-check rules).
  • Missing Docs on Newer Methods: The Transliteration class has better examples online (see en_transliteration.php in GitHub examples). Check the demo list for usage clues when PHPDoc is sparse.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport