PHPackages                             vnuswilliams/laravel-autolang - 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. [Localization &amp; i18n](/categories/localization)
4. /
5. vnuswilliams/laravel-autolang

ActiveLibrary[Localization &amp; i18n](/categories/localization)

vnuswilliams/laravel-autolang
=============================

Automatically scan blade files, extract hardcord UI text, wrap laravel trasnlation helpers, and generate JSON and/or PHP trasnlations files

v1.2.1(2w ago)00MITPHPPHP ^8.2||^8.3||^8.4CI passing

Since May 23Pushed 2w ago1 watchersCompare

[ Source](https://github.com/vnuswilliams/laravel-autolang)[ Packagist](https://packagist.org/packages/vnuswilliams/laravel-autolang)[ Docs](https://github.com/vnuswilliams/laravel-autolang)[ RSS](/packages/vnuswilliams-laravel-autolang/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (5)Versions (14)Used By (0)

 [ ![Latest Version](https://camo.githubusercontent.com/edc818c6589b450dc59cff548e83215eb79e574277e20774312858fd1b0fcb40/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f766e757377696c6c69616d732f6c61726176656c2d6175746f6c616e67) ](https://packagist.org/packages/vnuswilliams/laravel-autolang) [ ![Total Downloads](https://camo.githubusercontent.com/67b6cdcc892da7ea7debcf8f866559667d5ac07d841c86508862b57adc138536/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f766e757377696c6c69616d732f6c61726176656c2d6175746f6c616e67) ](https://packagist.org/packages/vnuswilliams/laravel-autolang) [ ![PHP Version](https://camo.githubusercontent.com/d00b8703d0dcdd20c854575266381626fda79648811e3e7ea658347f9fd7026b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f766e757377696c6c69616d732f6c61726176656c2d6175746f6c616e67) ](https://packagist.org/packages/vnuswilliams/laravel-autolang) [ ![Laravel Version](https://camo.githubusercontent.com/dc62a42bfb7742d9b2fd3a19190c56b3d4d183f1cd30f0b3b295130f987450fb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31302532302d2d25323031332d726564) ](https://packagist.org/packages/vnuswilliams/laravel-autolang) [ ![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e) ](LICENSE.md) [ ![Tests](https://github.com/vnuswilliams/laravel-autolang/workflows/Tests/badge.svg) ](https://github.com/vnuswilliams/laravel-autolang/actions) [ ![Code Style](https://camo.githubusercontent.com/13f79cacad2984232f3e500d7def5bbd4a36c3e8713554e335ef14a999904716/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64652532307374796c652d50696e742d626c7565) ](https://github.com/vnuswilliams/laravel-autolang)

Laravel AutoLang
================

[](#laravel-autolang)

Laravel AutoLang automates the internationalization of your Blade views by:

- detecting hardcoded text inside `*.blade.php` templates,
- replacing this text with `{{ __('...') }}`,
- automatically adding missing entries into `lang/.json` or `lang//.php`.

The goal is to reduce manual work when setting up or maintaining multilingual support in a Laravel project.

---

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Configuration](#configuration)
- [Available Command](#available-command)
- [Usage Examples](#usage-examples)
- [Supported Scenarios](#supported-scenarios)
- [Ignored Cases / Known Limitations](#ignored-cases--known-limitations)
- [Recommended Team Workflow](#recommended-team-workflow)
- [Troubleshooting](#troubleshooting)
- [Laravel i18n Best Practices](#laravel-i18n-best-practices)

---

Features
--------

[](#features)

- Scan one or multiple Blade view directories.
- Detect text segments between HTML tags.
- Automatically replace text with `{{ __('Text') }}`.
- Generate/update translations in JSON or PHP format.
- Automatically name PHP translation files based on scanned Blade filenames.
- Deduplicate existing translation keys.
- Preview mode (`--dry`) before writing changes.
- Interactive confirmation (disable with `--force`).

---

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

[](#requirements)

- PHP version compatible with your Laravel version.
- A Laravel project using the standard structure (`resources/views`, `lang`, etc.).
- Write permissions for view files and language directories.

---

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

[](#installation)

```
composer require --dev vnuswilliams/laravel-autolang
```

---

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

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --provider="VnusWilliams\\LaravelAutoLang\\LaravelAutoLangServiceProvider" --tag=config
```

The `config/lang-auto.php` file exposes:

```
return [
    'paths' => [
        resource_path('views'),
    ],

    'extensions' => [
        '.blade.php',
    ],

    'locale' => 'en',
    'output' => 'json',
];
```

### `paths`

[](#paths)

List of directories to scan for `*.blade.php` files.

Example with multiple locations:

```
'paths' => [
    resource_path('views'),
    base_path('Modules/Blog/resources/views'),
],
```

### `extensions`

[](#extensions)

List of allowed file extensions during scanning.

Default:

```
'extensions' => ['.blade.php'],
```

### `locale`

[](#locale)

Target locale for translation files.

```
'locale' => 'fr',
```

### `output`

[](#output)

Output format: `json` (default) or `php`.

When `output = php`, the PHP translation filename is automatically derived from the scanned Blade filename — no extra configuration is required.

---

Automatic PHP Translation File Naming
-------------------------------------

[](#automatic-php-translation-file-naming)

When `output = php`, the translation file name is generated from the Blade filename according to these rules:

Blade FileTranslation File`welcome.blade.php``lang//welcome.php``leave-balance.blade.php``lang//leavebalance.php``⚡welcome-to.blade.php``lang//welcometo.php``My_Cool View.blade.php``lang//mycoolview.php`**Applied rules:**

1. Extensions are removed (`.blade.php` → two passes).
2. The result is converted to lowercase.
3. Any non-Unicode letter or digit character is removed.

With `--all`, each Blade file produces its own PHP translation file.

---

Available Command
-----------------

[](#available-command)

```
php artisan lang:auto {path?}
```

- `path` (optional): relative path from `resources/views` (or configured root path), without extension.
- If `path` is missing, the command asks interactively.
- If the provided path starts with `/`, the leading slash is automatically removed.

Example paths:

- `welcome` ⟶ searches `resources/views/welcome.blade.php`
- `pages/welcome` ⟶ searches `resources/views/pages/welcome.blade.php`

Options:

- `--all` : scan the entire configured directory recursively.
- `--locale=fr` : temporarily override the output locale.
- `--output=json|php` : choose output format (overrides config).
- `--dry` : simulate execution without modifying files.
- `--force` : apply changes without confirmation.

With `--all`, an extra confirmation is requested before starting the global scan (unless `--force` is present).

Full signature:

```
php artisan lang:auto {path?} {--all} {--locale=} {--output=} {--dry} {--force}
```

---

Usage Examples
--------------

[](#usage-examples)

### 1) First Translation Migration (JSON)

[](#1-first-translation-migration-json)

```
php artisan lang:auto --locale=fr
```

- The package detects hardcoded strings.
- Displays detected strings and impacted files.
- After confirmation, updates views and `lang/fr.json`.

### 2) PHP Output — Automatic Naming

[](#2-php-output--automatic-naming)

```
php artisan lang:auto leave-balance --locale=fr --output=php --force
```

- Scans `resources/views/leave-balance.blade.php`.
- Automatically creates/updates `lang/fr/leavebalance.php`.

### 3) Global PHP Scan

[](#3-global-php-scan)

```
php artisan lang:auto --all --locale=fr --output=php --force
```

- Scans all views.
- Each view generates its own PHP translation file:

    - `welcome.blade.php` → `lang/fr/welcome.php`
    - `hr/leave-balance.blade.php` → `lang/fr/leavebalance.php`

### 4) Verification Before Commit (Local CI)

[](#4-verification-before-commit-local-ci)

```
php artisan lang:auto --dry
```

- No files modified.
- Allows reviewing pending changes before applying them.

### 5) Non-Interactive Execution (Scripts / CI)

[](#5-non-interactive-execution-scripts--ci)

```
php artisan lang:auto --force
```

---

Supported Scenarios
-------------------

[](#supported-scenarios)

### Simple HTML Text

[](#simple-html-text)

Before:

```
Welcome
```

After:

```
{{ __('Welcome') }}
```

### Preserving Surrounding Spaces

[](#preserving-surrounding-spaces)

Before:

```
   Hello world
```

After:

```
   {{ __('Hello world') }}
```

### Apostrophes

[](#apostrophes)

Before:

```
It's ready
```

After:

```
{{ __('It\'s ready') }}
```

### JSON Translation Deduplication

[](#json-translation-deduplication)

If a key already exists in `lang/.json`, it is not duplicated. The file is alphabetically sorted to keep clean diffs.

---

Ignored Cases / Known Limitations
---------------------------------

[](#ignored-cases--known-limitations)

To avoid false positives, some blocks are ignored during extraction:

- `...`
- `...`
- `@php ... @endphp` blocks
- Blade expressions `{{ ... }}` and `{!! ... !!}`
- Blade directives (`@if`, `@foreach`, etc.)
- Blade components `` and `...`

### Important Limitations

[](#important-limitations)

- The package targets text between tags (`>text $name])`) for dynamic content.
- Add QA/product review for translations.

---

License
-------

[](#license)

MIT

---

Reverse Command — `--reverse`
-----------------------------

[](#reverse-command----reverse)

The `--reverse` command allows reverting changes: it reads translation values, replaces `{{ __('...') }}` helpers with raw text in Blade views, then removes used keys from translation files.

```
php artisan lang:auto {path?} --reverse
php artisan lang:auto --all --reverse
```

The flag does not take any value. Everything relies on the configuration (`locale`, `output`).

---

### Workflow Depending on `output`

[](#workflow-depending-on-output)

**`json` mode**

1. Load `lang/.json`
2. In targeted Blade files, resolve each `{{ __("...") }}` → replace with raw value
3. Remove used keys from the `.json` file and rewrite it

**`php` mode**

1. List available `.php` files in `lang//` and ask for selection interactively
2. Load translations from the selected file
3. In targeted Blade files, resolve each `{{ __("...") }}` → replace with raw value
4. Remove used keys from the `.php` file and rewrite it

---

### Key Resolution

[](#key-resolution)

The last segment after the final `.` is used as the lookup key inside translation files.

Blade HelperResolved Key`{{ __("welcome") }}``welcome``{{ __("messages.welcome") }}``welcome``{{ __("a.b.c.myKey") }}``myKey`If a key is not found in the translation file, the helper remains unchanged.

---

### Full Example

[](#full-example)

Blade before:

```
{{ __("welcome") }}
{{ __("messages.farewell") }}
```

`lang/fr.json`:

```
{
    "farewell": "Goodbye",
    "welcome": "Welcome"
}
```

After:

```
php artisan lang:auto welcome --reverse --locale=fr
```

Blade result:

```
Welcome
Goodbye
```

`lang/fr.json` after cleanup:

```
{}
```

---

### Compatible Options With `--reverse`

[](#compatible-options-with---reverse)

OptionBehavior`--dry`Preview without modifying files`--force`Apply without confirmation`--all`Process all configured views`--locale=fr`Temporarily override locale`--output=json|php`Temporarily override output format---

### Limitations

[](#limitations)

- Only keys present in the selected translation file are resolved.
- HTML attributes (`placeholder`, `title`, etc.) are not handled — consistent with forward behavior.
- If `lang//` contains no `.php` files, the command stops with a warning.

```

```

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance97

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

2

Last Release

16d ago

PHP version history (2 changes)1.0.0PHP ^8.2

v1.2.1PHP ^8.2||^8.3||^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/cb95d945953ad8dee968c72eafece2596b0887a2b4301a14103e068de017b73b?d=identicon)[Vnus](/maintainers/Vnus)

---

Top Contributors

[![vnuswilliams](https://avatars.githubusercontent.com/u/106296680?v=4)](https://github.com/vnuswilliams "vnuswilliams (25 commits)")

---

Tags

laraveli18ntrasnlationsautolangautomate translations

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vnuswilliams-laravel-autolang/health.svg)

```
[![Health](https://phpackages.com/badges/vnuswilliams-laravel-autolang/health.svg)](https://phpackages.com/packages/vnuswilliams-laravel-autolang)
```

###  Alternatives

[laravel/ai

The official AI SDK for Laravel.

9782.1M153](/packages/laravel-ai)[erag/laravel-lang-sync-inertia

A powerful Laravel package for syncing and managing language translations across backend and Inertia.js (Vue/React) frontends, offering effortless localization, auto-sync features, and smooth multi-language support for modern Laravel applications.

4721.5k](/packages/erag-laravel-lang-sync-inertia)[illuminate/queue

The Illuminate Queue package.

20432.2M1.5k](/packages/illuminate-queue)[moonshine/moonshine

Laravel administration panel

1.3k239.9k72](/packages/moonshine-moonshine)[mariuzzo/laravel-js-localization

Laravel Localization in JavaScript

6094.0M3](/packages/mariuzzo-laravel-js-localization)[erag/laravel-disposable-email

A Laravel package to detect and block disposable email addresses.

249143.0k](/packages/erag-laravel-disposable-email)

PHPackages © 2026

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