abrarali/laravel-ai-polyglot

Laravel Polyglot: context-aware, AI-powered localization for Laravel 11+.

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/abrarali/laravel-ai-polyglot

v0.1.0 2025-12-06 07:59 UTC

This package is auto-updated.

Last update: 2025-12-06 08:21:11 UTC


README

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/docs in your app.

Features

  • 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.).
  • Safe CLI workflow

    • polyglot:scan to discover missing keys.
    • polyglot:translate with --dry-run, --group, --route, --path.
    • polyglot:status to measure coverage.
    • polyglot:clean with --dry-run to 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: pending vs approved, reused as translation memory.
  • 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/docs for your whole team.

Requirements

  • 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

Installation

Install via Composer in your Laravel application:

composer require abrarali/laravel-polyglot

Publish the config file (optional but recommended):

php artisan vendor:publish --provider="LaravelPolyglot\\PolyglotServiceProvider" --tag=config

This will create config/polyglot.php in your app.

Configuration

1. Driver & OpenAI

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/v1

You can also use the dummy driver for local development and testing.

2. Fallback locale

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',
    // ...
];

Quickstart

This is the shortest path from install to seeing Polyglot in action.

1. Add some __() calls

In any Blade view (for example, your own page or the demo page), reference translation keys:

{{ __('messages.save') }}
{{ __('messages.login_now') }}

2. Scan for missing keys

See which keys are missing in your fallback locale:

php artisan polyglot:scan --dry-run

Then let Polyglot create placeholders in lang/en:

php artisan polyglot:scan

3. Generate translations

Translate from en to a target locale, e.g. Spanish:

php artisan polyglot:translate es

Or limit to a specific group:

php artisan polyglot:translate de --group=messages

Or 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.php

Tip: Add --dry-run to preview what would happen without calling the API or writing files.

4. Review & approve

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.

5. Keep things clean

Check coverage for a locale:

php artisan polyglot:status es

Preview unused keys (safe mode):

php artisan polyglot:clean --dry-run

After checking the output, archive unused keys:

php artisan polyglot:clean

Unused keys are moved to lang/archive/{locale}/{group}.php, not deleted.

In-app documentation

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/docs
  • https://your-app.test/polyglot/documentation In Localhost
  • http://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.

Contributing

Issues and pull requests are welcome.

Please include reproduction steps and your Laravel/PHP versions when reporting bugs.

License

Laravel Polyglot is open-sourced software licensed under the MIT license.