PHPackages                             artryazanov/artisan-translator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. artryazanov/artisan-translator

ActiveLaravel-package[Templating &amp; Views](/categories/templating)

artryazanov/artisan-translator
==============================

A Laravel package to extract Blade translation strings and translate them using AI.

v1.0.5(2mo ago)1165↓100%MITPHPPHP ^8.2CI passing

Since Aug 12Pushed 3w agoCompare

[ Source](https://github.com/artryazanov/artisan-translator)[ Packagist](https://packagist.org/packages/artryazanov/artisan-translator)[ RSS](/packages/artryazanov-artisan-translator/feed)WikiDiscussions main Synced today

READMEChangelog (8)Dependencies (12)Versions (10)Used By (0)

Artisan Translator for Laravel
==============================

[](#artisan-translator-for-laravel)

**Artisan Translator** streamlines the localization workflow in Laravel applications. It automates the extraction of strings from Blade templates, translates them using Google's Gemini AI, and helps keep your language files clean by removing unused keys.

[![Tests](https://github.com/artryazanov/artisan-translator/actions/workflows/run-tests.yml/badge.svg)](https://github.com/artryazanov/artisan-translator/actions/workflows/run-tests.yml)[![Coverage](.github/statuses/coverage.svg)](https://github.com/artryazanov/artisan-translator/actions/workflows/run-coverage.yml)[![Pint](https://github.com/artryazanov/artisan-translator/actions/workflows/run-pint.yml/badge.svg)](https://github.com/artryazanov/artisan-translator/actions/workflows/run-pint.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/86755558e775c53f15e63fc2b58ffdb7716e0e2910dc4ee3541e547cbe8affe2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6172747279617a616e6f762f6172746973616e2d7472616e736c61746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/artryazanov/artisan-translator)[![Total Downloads](https://camo.githubusercontent.com/915d5999c655e09ecb8ecf096cf63668815e060849d549e8bcbb09f0063a4b0f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6172747279617a616e6f762f6172746973616e2d7472616e736c61746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/artryazanov/artisan-translator)[![PHP Version](https://camo.githubusercontent.com/257c4c0e2a4eb053d613b62080256e28a95d51ba69d4b985bf9e1fbb88562d60/68747470733a2f2f706f7365722e707567782e6f72672f6172747279617a616e6f762f6172746973616e2d7472616e736c61746f722f726571756972652f7068703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/artryazanov/artisan-translator)[![Laravel Version](https://camo.githubusercontent.com/c72f8bd2dc45ca4c319fec3dea8e776f9bedaea774f7fc148ab68c9f2b5500a3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d313125324631322d7265643f7374796c653d666c61742d737175617265266c6f676f3d6c61726176656c)](https://laravel.com)[![License](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](LICENSE)

Key Features
------------

[](#key-features)

- **🔍 Automatic Extraction**: Scans Blade templates (`.blade.php`) for **raw text** wrapped in common helpers (e.g. `__('Hello')`), replaces them with translation keys, and saves the source strings to language files.
- **🤖 AI Translation**: Uses **Google Gemini** to translate your strings into multiple languages.
- **🚀 Batch Processing**: Translates strings in batches to optimize API usage and reduce costs/time.
- **🧹 Smart Cleanup**: Detects and removes translation keys that are no longer used in your codebase.
- **🛡️ Safe &amp; Robust**: Preserves HTML tags and Laravel placeholders (`:name`, `{count}`) during translation. Includes retry mechanisms for API stability.

Requirements
------------

[](#requirements)

- **PHP**: 8.2 or higher
- **Laravel**: 11.0+ or 12.0+

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require --dev artryazanov/artisan-translator
```

The package will automatically register its service provider.

### Setup

[](#setup)

1. **Get a Gemini API Key**: Obtain an API key from [Google AI Studio](https://aistudio.google.com/).
2. **Configure Environment**: Add the key to your `.env` file:

    ```
    GEMINI_API_KEY=your-api-key-here
    GEMINI_MODEL=gemma-3-27b-it
    ```
3. **(Optional) Publish Configuration**: Customise default settings by publishing the config file:

    ```
    php artisan vendor:publish --provider="Artryazanov\ArtisanTranslator\ArtisanTranslatorServiceProvider" --tag="config"
    ```

Usage
-----

[](#usage)

### 1. Extract Strings

[](#1-extract-strings)

Scan your `resources/views` directory to find static strings, replace them with translation keys in the Blade files, and save the original strings to your source language files (default: `en`).

```
php artisan translate:extract
```

**Options:**

- `--path=dir/name`: Limit scanning to a specific subdirectory within `resources/views`.
- `--dry-run`: Preview changes without modifying any files.
- `--force`: Overwrite existing keys in translation files if they overlap.

#### 📝 What strings are extracted?

[](#-what-strings-are-extracted)

The command scans for strings wrapped in `__('...')` or `@lang('...')`. It intelligently distinguishes between "plain text" that needs extraction and existing translation keys.

String TypeExampleActionReason**Plain Text**`__('Hello World')`✅ **Extract**Contains spaces or punctuation.**Plain Text**`@lang('Click here')`✅ **Extract**Contains spaces.**Existing Key**`__('messages.welcome')`❌ **Ignore**Looks like a key (dots, no spaces).**Existing Key**`@lang('auth.failed')`❌ **Ignore**Looks like a key.**Existing Key**`__('forms/user.email')`❌ **Ignore**Looks like a key (slashes allowed).### 2. Translate with AI

[](#2-translate-with-ai)

Translate your extracted strings from the source language to one or more target languages using Gemini.

```
php artisan translate:ai --targets=fr --targets=de
```

**Arguments &amp; Options:**

- `source` (optional): Specify source language (defaults to `source_language` in config, usually `en`).
- `--targets`: **Required**. The target language code(s) (e.g., `fr`, `es`, `de`). Can be repeated.
- `--force`: Overwrite existing translations in the target files.

> **Note**: If you have `mcamara/laravel-localization` installed, the package can automatically detect supported locales if you omit `--targets`.

### 3. Cleanup Unused Translations

[](#3-cleanup-unused-translations)

Keep your language files tidy by removing keys that are no longer referenced in your codebase.

```
php artisan translations:cleanup --dry-run
```

**Options:**

- `--dry-run`: List unused keys without deleting them (Recommended first step).
- `--force`: Skip the confirmation prompt and delete immediately.

Configuration
-------------

[](#configuration)

### Main Config (`config/artisan-translator.php`)

[](#main-config-configartisan-translatorphp)

OptionEnv VariableDefaultDescription`source_language``ARTISAN_TRANSLATOR_SOURCE_LANG``en`The source language of your application.`lang_root_path``ARTISAN_TRANSLATOR_LANG_ROOT``blade`Subdirectory under `resources/lang/{locale}` where files are stored.`ai_request_delay_seconds``ARTISAN_TRANSLATOR_AI_DELAY``2.0`Minimum delay between AI API requests to avoid rate limits.`gemini.api_key``GEMINI_API_KEY`-Your Google Gemini API Key.`gemini.model``GEMINI_MODEL``gemma-3-27b-it`The AI model to use.### Cleaner Config (`config/translation-cleaner.php`)

[](#cleaner-config-configtranslation-cleanerphp)

- **`scan_paths`**: Directories to scan for translation usage (defaults to `app_path()` and `resource_path('views')`).
- **`file_extensions`**: File types to scan (defaults to `*.php`, `*.blade.php`).
- **`translation_functions`**: Functions to look for (e.g., `__`, `trans`, `@lang`).

Supported AI Models
-------------------

[](#supported-ai-models)

You can use any string supported by the Gemini API, or one of the built-in Enum values:

- `gemini-3.0-pro`
- `gemini-3.0-flash`
- `gemini-2.5-pro`
- `gemini-2.5-flash`
- `gemini-2.5-flash-lite`
- `gemma-3-27b-it` (Default)

Testing
-------

[](#testing)

Run the test suite to ensure everything is working correctly:

```
composer test
```

License
-------

[](#license)

MIT. See [LICENSE](LICENSE).

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance91

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 91.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~22 days

Recently: every ~6 days

Total

8

Last Release

68d ago

Major Versions

v0.1.1 → v1.0.02025-12-19

### Community

Maintainers

![](https://www.gravatar.com/avatar/6357ca96399697b30326b317cf64cb85eb01005fb296cf50176d4008cf448135?d=identicon)[artryazanov](/maintainers/artryazanov)

---

Top Contributors

[![artryazanov](https://avatars.githubusercontent.com/u/4519328?v=4)](https://github.com/artryazanov "artryazanov (42 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

aiai-assistedartisanbladegeminigoogle-geminii18nlaravellaravel-packagelocalizationphptranslationlaravellocalizationtranslationaiartisanGemini

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/artryazanov-artisan-translator/health.svg)

```
[![Health](https://phpackages.com/badges/artryazanov-artisan-translator/health.svg)](https://phpackages.com/packages/artryazanov-artisan-translator)
```

###  Alternatives

[blade-ui-kit/blade-icons

A package to easily make use of icons in your Laravel Blade views.

2.4k31.8M214](/packages/blade-ui-kit-blade-icons)[tio/laravel

Add this package to localize your Laravel application (PHP, JSON or GetText).

170309.5k](/packages/tio-laravel)[smousss/laravel-globalize

Make Laravel projects translatable in a matter of seconds!

2262.2k](/packages/smousss-laravel-globalize)[chimit/prompt

Manage AI prompts in Blade style.

394.4k](/packages/chimit-prompt)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
