TransSFC is a Laravel package for translating Blade components directly within components using @TransSFC()
, auto-extracting texts into language files.
- Laravel
^11
- Node.js
^20
You can install the package via Composer:
composer require iammarjamal/transsfc
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.
You can now use @useTheme()
and @TransSFC()
in any Blade file within the resources/views
directory.
<div>
...
<p>@useTheme('hello_world')</p>
</div>
@TransSFC('ar')
[
'hello_world' => 'اهلاً بالعالم',
]
@endTransSFC
@TransSFC('en')
[
'hello_world' => 'Hello World',
]
@endTransSFC
-
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]
.
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.
The MIT License (MIT). Please see License File for more information.