iammarjamal/transsfc

A Laravel package for translating Blade components directly within components using @TransSFCs(), auto-extracting texts into language files.

1.0.1 2025-04-01 00:54 UTC

This package is auto-updated.

Last update: 2025-04-01 00:55:48 UTC


README

TransSFC

TransSFC

TransSFC is a Laravel package for translating Blade components directly within components using @TransSFC(), auto-extracting texts into language files.

📌 Requirements

  • Laravel ^11
  • Node.js ^20

🚀 Installation

You can install the package via Composer:

composer require iammarjamal/transsfc

📚 Usage

1⃣ Start the Translation Watcher

Run the following command in the terminal to activate the Node.js watcher:

php artisan lang:serve

This watcher monitors Blade files and automatically extracts translatable text into Laravel's language files.

2⃣ Define Translations in Blade Files

You can now use @useTheme() and @TransSFC() in any Blade file within the resources/views directory.

✨ Example Usage

<div>
   ...
   <p>@useTheme('hello_world')</p>
</div>

@TransSFC('ar')
[
   'hello_world' => 'اهلاً بالعالم',
]
@endTransSFC

@TransSFC('en')
[
   'hello_world' => 'Hello World',
]
@endTransSFC

🔍 How It Works

  1. Translating Text:

    • The @useTheme('hello_world') directive retrieves the corresponding translation for the active language.
    • The @TransSFC('ar') and @TransSFC('en') blocks define translations for Arabic (ar) and English (en).
  2. Automatic Language File Updates:

    • The watcher reads these Blade files and updates the Laravel language files.
    • Translations are stored in lang/[lang]/app.php using the format [sfc.pathBladeFile.key].

📝 Example of the Generated Language File (lang/en/app.php)

return [
   'sfc.home.pages.index.hello_world' => 'Hello World',
];

This makes it easy to manage translations directly within Blade files while ensuring they are structured within Laravel's language system.

Credits

License

The MIT License (MIT). Please see License File for more information.