If you find PHPFlasher useful, we would greatly appreciate your support in the form of a star rating ⭐ on GitHub or by sharing the project on Twitter click here. Your feedback helps us keep the package up-to-date and well-maintained. Thank you


PHPFlasher supports right-to-left languages like Arabic and Hebrew which are written from right to left.

RTL Option

class BookController
{
    public function save(FlasherInterface $flasher)
    {
        $flasher
            ->option('rtl', true)
            ->addSuccess('تم حفظ الكتاب بنجاح'); // "Book saved successfully" in Arabic

Frameworks

For Frameworks like Symfony and Laravel, you don’t to worry about text direction because PHPFlasher will detect it automatically.

PHPFlasher rely on the translation service to determine the current language and then determine its direction.

So all you need to do is to enable the translation service in your framework’s config file if it’s not already enabled.


Configuration

symfony

# config/packages/translation.yaml
framework:
  default_locale: 'en' # 'ar', 'fr' etc. (default: 'en')
  translator:
    enabled: true # enable or disable the translator (default: true)
    default_path: '%kernel.project_dir%/translations' # where to look for translation files
    fallbacks:
        - en # fallback to 'en' if translation is not found for the current locale

laravel

# config/app.php
return [
    
    /*
    |--------------------------------------------------------------------------
    | Application Locale Configuration
    |--------------------------------------------------------------------------
    |
    | The application locale determines the default locale that will be used
    | by the translation service provider. You are free to set this value
    | to any of the locales which will be supported by the application.
    |
    */
    
    'locale' => 'en',
    
    /*
    |--------------------------------------------------------------------------
    | Application Fallback Locale
    |--------------------------------------------------------------------------
    |
    | The fallback locale determines the locale to use when the current one
    | is not available. You may change the value to correspond to any of
    | the language folders that are provided through your application.
    |
    */
    
    'fallback_locale' => 'en',
];

Usage

Let’s say at this point you already have the translator service enabled in your config file and the locale is set.

class BookController
{
    public function save(FlasherInterface $flasher)
    {
        $flasher
            ->addSuccess('Book saved successfully')

PHPFlasher will automatically detect the current language and then determine its direction.

Younes

PHPFlasher is a project by Younes KHOUBZA.