iammarjamal / transsfc
A Laravel package for translating Blade components directly within components using @TransSFCs(), auto-extracting texts into language files.
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Language:JavaScript
Requires
- php: ^8.4
- illuminate/contracts: ^10.0||^11.0||^12.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^10.0.0||^9.0.0||^8.22.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- spatie/laravel-ray: ^1.35
README
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
-
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
).
- The
-
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.