iammarjamal/transsfc 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

iammarjamal/transsfc

最新稳定版本:1.0.1

Composer 安装命令:

composer require iammarjamal/transsfc

包简介

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

README 文档

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.

统计信息

  • 总下载量: 15
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: JavaScript

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-22