hendriarga/blade-localizer

Auto-scan and localize Laravel Blade UI text into language files

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/hendriarga/blade-localizer

dev-main 2025-06-21 11:16 UTC

This package is auto-updated.

Last update: 2025-12-21 12:22:22 UTC


README

Blade Localizer is a Laravel package that scans your Blade .blade.php files, extracts UI strings, and adds them to your lang/{locale}/ui.php or ui.json translation files. It also supports auto-replacing static text with the __() helper and translating them using the Google Translate API.

✨ Features

  • 🔍 Scan HTML tags like div, span, label, a, button, p, and even custom components like <x-*>
  • 🪄 Auto-replace static text with {{ __('...') }}
  • 🌐 Generate lang/{locale}/ui.php and ui.json files
  • 🌍 Automatic translation support via Google Translate API
  • 🧩 Detect translatable attributes like placeholder, title, aria-label, etc.
  • 🚫 Optionally skip already-translated strings using __('...')
  • ♻️ Avoids duplicate keys and appends new ones instead of overwriting
  • 🧠 Caches translation results for performance

🚀 Installation

composer require hendriarga/blade-localizer

📖 Usage

1. Publish the config file

php artisan vendor:publish --tag=blade-localizer

4. Run the blade:localize Artisan command

php artisan localize:blade

This command will scan your Blade files, extract UI strings, and add them to your lang/{locale}/ui.php or ui.json files. It will also automatically replace static text with the __() helper and translate them using the Google Translate API.

📝 Configuration

You can customize the behavior of the package by editing the config/blade-localizer.php file.

Option Description Default
locales An array of locales to generate language files for. ['en']
views An array of folders to scan for Blade files. ['resources/views']
filename The name of the language file. ui.php
skip_keywords An array of keywords to skip when extracting UI strings. []
path The path to the language file. Set to false to generate a new file. false

📝 License

The package is open-sourced software licensed under the MIT license. Feel free to use, modify, and distribute this package as long as you follow the license terms.