Context-aware, AI-powered localization for Laravel. Turn your existing English UI into a truly multilingual product without drowning in thousands of translation keys.
Laravel Polyglot scans your Blade views for __() usages, feeds real code context to an AI translator, and writes clean PHP lang files for any locale supported by Laravel.
For a full, step-by-step guide (with screenshots), install the package and open
/polyglot/docsin your app.
-
Context-aware translations
- Scans your Blade views and passes HTML/code context to the AI driver.
- Avoids classic mistakes like translating "save" as a noun when it should be a verb.
-
Works with any language
- Uses your fallback locale (usually
en) as the source of truth. - Generates translations for any Laravel locale (
ar,he,it,my, etc.).
- Uses your fallback locale (usually
-
Safe CLI workflow
polyglot:scanto discover missing keys.polyglot:translatewith--dry-run,--group,--route,--path.polyglot:statusto measure coverage.polyglot:cleanwith--dry-runto archive unused keys.
-
Review & approval UI
- Built-in dashboard at
/polyglot/dashboard. - Optional Filament v4 page for reviewing and approving pending translations.
- Per-key metadata:
pendingvsapproved, reused as translation memory.
- Built-in dashboard at
-
Developer-first
- Plain PHP lang files under
lang/{locale}/{group}.php. - No vendor lock-in; you can always edit files manually.
- In-app docs at
/polyglot/docsfor your whole team.
- Plain PHP lang files under
- PHP:
^8.2 - Laravel: 11.x (and future 12.x once released)
- Package constraints:
illuminate/support^11.0|^12.0,illuminate/translation^11.0|^12.0
- Package constraints:
Install via Composer in your Laravel application:
composer require abrarali/laravel-polyglotPublish the config file (optional but recommended):
php artisan vendor:publish --provider="LaravelPolyglot\\PolyglotServiceProvider" --tag=configThis will create config/polyglot.php in your app.
Set your driver and API details in .env:
POLYGLOT_DRIVER=openai
POLYGLOT_OPENAI_API_KEY=your-key-here
POLYGLOT_OPENAI_MODEL=gpt-4.1-mini
# POLYGLOT_OPENAI_BASE_URL=https://api.openai.com/v1You can also use the dummy driver for local development and testing.
Polyglot always translates from the fallback locale into your target languages.
// config/app.php
'fallback_locale' => 'en',Make sure your English messages are defined, for example:
// lang/en/messages.php
return [
'save' => 'Save',
'login_now' => 'Login now',
// ...
];This is the shortest path from install to seeing Polyglot in action.
In any Blade view (for example, your own page or the demo page), reference translation keys:
{{ __('messages.save') }}
{{ __('messages.login_now') }}See which keys are missing in your fallback locale:
php artisan polyglot:scan --dry-runThen let Polyglot create placeholders in lang/en:
php artisan polyglot:scanTranslate from en to a target locale, e.g. Spanish:
php artisan polyglot:translate esOr limit to a specific group:
php artisan polyglot:translate de --group=messagesOr limit to a specific view path (keys that appear in that file):
php artisan polyglot:translate it \
--group=messages \
--path=resources/views/polyglot-demo-second.blade.phpTip: Add
--dry-runto preview what would happen without calling the API or writing files.
Open the built-in dashboard:
/polyglot/dashboard
There you can:
- See pending vs approved translations per locale.
- Edit text inline.
- Approve single keys or bulk-approve all pending items.
If you use Filament v4, you can also enable the Polyglot Review page in your admin panel.
Check coverage for a locale:
php artisan polyglot:status esPreview unused keys (safe mode):
php artisan polyglot:clean --dry-runAfter checking the output, archive unused keys:
php artisan polyglot:cleanUnused keys are moved to lang/archive/{locale}/{group}.php, not deleted.
Laravel Polyglot ships with a modern, SaaS-style documentation page that lives inside your app.
By default, after installing the package and visiting your app in a browser:
https://your-app.test/polyglot/docshttps://your-app.test/polyglot/documentationIn Localhosthttp://127.0.0.1:8000/polyglot/docs
You can change the route prefix and middleware in config/polyglot.php under the ui section.
The in-app docs include:
- A visual overview of the workflow.
- Copy-pasteable CLI commands.
- Tips for teams and CI.
Issues and pull requests are welcome.
- Source & issues: GitHub – AbrarAli14/laravel-polyglot
Please include reproduction steps and your Laravel/PHP versions when reporting bugs.
Laravel Polyglot is open-sourced software licensed under the MIT license.