PHPackages                             silalahi/laravel-translation-extractor - 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. silalahi/laravel-translation-extractor

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

silalahi/laravel-translation-extractor
======================================

Extract translation keys from Blade views and generate language files

0.3.0(6mo ago)022[1 PRs](https://github.com/silalahi/laravel-translation-extractor/pulls)MITPHPPHP ^8.1CI passing

Since Nov 12Pushed 2mo agoCompare

[ Source](https://github.com/silalahi/laravel-translation-extractor)[ Packagist](https://packagist.org/packages/silalahi/laravel-translation-extractor)[ RSS](/packages/silalahi-laravel-translation-extractor/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (5)Versions (6)Used By (0)

Laravel Translation Extractor
=============================

[](#laravel-translation-extractor)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b97fe599af3d9ddf8921bf23e990e9609588cd1dd985c9d610ca7882499b2a89/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73696c616c6168692f6c61726176656c2d7472616e736c6174696f6e2d657874726163746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/silalahi/laravel-translation-extractor)[![Total Downloads](https://camo.githubusercontent.com/2d166cccf99a8996f93e1e20bf8e6f027b343ead39405b4e9c213189e90d79e7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73696c616c6168692f6c61726176656c2d7472616e736c6174696f6e2d657874726163746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/silalahi/laravel-translation-extractor)

A Laravel package to automatically extract translation keys from your views and generate language files. Say goodbye to manually creating translation files!

Features
--------

[](#features)

- 🔍 **Automatic Extraction**: Scans your views for `__()`, `trans()`, and `@lang()` functions
- 🤖 **AI-Powered Translation**: Automatically translate extracted keys using OpenAI, DeepL, or Google Translate
- 🌍 **Multi-locale Support**: Generate translation files for any locale
- 📁 **Configurable Paths**: Scan custom directories beyond just views
- 🔄 **Preserve Existing**: Keeps your existing translations intact when re-running
- 📊 **Statistics**: Shows translation progress and completion percentage
- 🎯 **Context-Aware**: Groups related keys for consistent terminology
- ⚙️ **Highly Configurable**: Customize function names, paths, and more

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

[](#requirements)

- PHP 8.1 or higher
- Laravel 10.x, 11.x, or 12.x

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

[](#installation)

You can install the package via composer:

```
composer require silalahi/laravel-translation-extractor
```

Publish the configuration file:

```
php artisan vendor:publish --tag=translation-extractor-config
```

This will create a `config/translation-extractor.php` file.

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

Extract translations for the default locale (configured in config file):

```
php artisan translations:extract
```

### Extract for Specific Locale

[](#extract-for-specific-locale)

```
php artisan translations:extract --locale=id
```

### Force Overwrite

[](#force-overwrite)

By default, existing translations are preserved. Use `--force` to overwrite:

```
php artisan translations:extract --force
```

### AI-Powered Translation

[](#ai-powered-translation)

Automatically translate extracted keys using AI providers:

```
php artisan translations:extract --locale=id --translate
```

**Supported Providers:**

- OpenAI (GPT-4, GPT-3.5)
- DeepL
- Google Translate

**Setup:**

1. Add API keys to your `.env` file:

```
# For OpenAI
TRANSLATION_AI_ENABLED=true
TRANSLATION_AI_PROVIDER=openai
OPENAI_API_KEY=sk-...

# For DeepL
TRANSLATION_AI_PROVIDER=deepl
DEEPL_API_KEY=your-deepl-key

# For Google Translate
TRANSLATION_AI_PROVIDER=google
GOOGLE_TRANSLATE_API_KEY=your-google-key
```

2. Optional: Add domain context for better accuracy:

```
TRANSLATION_AI_DOMAIN="medical clinic management"
```

**Features:**

- Only translates keys with empty values (preserves manual edits)
- Groups related keys for consistent terminology
- Graceful error handling with detailed logs
- Batch processing for API efficiency

How It Works
------------

[](#how-it-works)

The package scans your view files looking for translation function calls:

```
// In your Blade views
__('I love programming.')
{{ __('Welcome to our website') }}
@lang('Hello World')
trans('Good morning')
```

It then generates a JSON file in your `lang` directory:

```
// lang/id.json
{
    "Good morning": "",
    "Hello World": "",
    "I love programming.": "",
    "Welcome to our website": ""
}
```

You can then add your translations:

```
// lang/id.json
{
    "Good morning": "Selamat pagi",
    "Hello World": "Halo Dunia",
    "I love programming.": "Saya suka pemrograman",
    "Welcome to our website": "Selamat datang di website kami"
}
```

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

[](#configuration)

The `config/translation-extractor.php` file provides extensive configuration options:

```
return [
    // Default locale for extraction (creates lang/{locale}.json)
    'locale' => 'id',

    // Directories to scan
    'paths' => [
        resource_path('views'),
        // Add more paths as needed
    ],

    // Translation functions to look for
    'functions' => [
        '__',
        'trans',
        '@lang',
    ],

    // File extensions to scan
    'extensions' => [
        'php',
        'blade.php',
    ],

    // Directories to exclude
    'exclude' => [
        'vendor',
        'node_modules',
        'storage',
    ],

    // Preserve existing translations
    'preserve_existing' => true,

    // Sort keys alphabetically
    'sort_keys' => true,
];
```

Advanced Usage
--------------

[](#advanced-usage)

### Scanning Custom Directories

[](#scanning-custom-directories)

You can scan additional directories by modifying the config:

```
'paths' => [
    resource_path('views'),
    app_path('Http/Controllers'), // Scan controllers too
    app_path('Services'),
],
```

### Custom Translation Functions

[](#custom-translation-functions)

If you use custom translation helper functions:

```
'functions' => [
    '__',
    'trans',
    '@lang',
    'translate', // Your custom function
    'my_trans',
],
```

### Multiple Locales Workflow

[](#multiple-locales-workflow)

Extract for multiple locales in sequence:

```
php artisan translations:extract --locale=id
php artisan translations:extract --locale=es
php artisan translations:extract --locale=fr
```

Tips &amp; Best Practices
-------------------------

[](#tips--best-practices)

1. **Run Regularly**: Extract translations during development to catch new keys
2. **Version Control**: Commit the generated files to track translation progress
3. **CI/CD Integration**: Add extraction to your CI pipeline to ensure no keys are missed
4. **Translation Services**: The generated JSON files are compatible with most translation services
5. **Keep Keys Simple**: Use clear, descriptive translation keys in English

Example Output
--------------

[](#example-output)

```
🔍 Scanning for translation keys...

✅ Found 24 unique translation keys.

📝 Sample keys:
   - Welcome to our application
   - Login to continue
   - Email Address
   - Password
   - Remember Me
   ... and 19 more

💾 Translations saved to: /path/to/your/project/lang/id.json

📊 Statistics:
+--------------+-------+
| Metric       | Value |
+--------------+-------+
| Total Keys   | 24    |
| Translated   | 18    |
| Untranslated | 6     |
| Progress     | 75%   |
+--------------+-------+

💡 Tip: Edit /path/to/your/project/lang/id.json to add translations for untranslated keys.

```

Testing
-------

[](#testing)

```
composer test
```

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Support
-------

[](#support)

If you find this package helpful, please consider:

- ⭐ Starring the repository
- 🐛 Reporting bugs
- 💡 Suggesting new features
- 🔀 Submitting pull requests

Roadmap
-------

[](#roadmap)

- Automatic translation using AI (OpenAI, DeepL, Google Translate) ✅
- Integration with translation services (OpenAI, DeepL, Google Translate) ✅
- Support for nested translation keys (dot notation)
- GUI for managing translations
- Support for pluralization rules
- Vue.js and React component scanning

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance78

Regular maintenance activity

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 75% 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

4

Last Release

182d ago

### Community

Maintainers

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

---

Top Contributors

[![silalahi](https://avatars.githubusercontent.com/u/1083028?v=4)](https://github.com/silalahi "silalahi (6 commits)")[![jsilalahi](https://avatars.githubusercontent.com/u/37064247?v=4)](https://github.com/jsilalahi "jsilalahi (2 commits)")

---

Tags

i18ninternationalizationlaravel-translationslocalizationtranslationtranslation-extractorlaravellocalizationi18ntranslationextract

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/silalahi-laravel-translation-extractor/health.svg)

```
[![Health](https://phpackages.com/badges/silalahi-laravel-translation-extractor/health.svg)](https://phpackages.com/packages/silalahi-laravel-translation-extractor)
```

###  Alternatives

[mariuzzo/laravel-js-localization

Laravel Localization in JavaScript

6073.9M3](/packages/mariuzzo-laravel-js-localization)[laravel-lang/publisher

Localization publisher for your Laravel application

2167.7M24](/packages/laravel-lang-publisher)[tio/laravel

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

170318.5k](/packages/tio-laravel)[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.

3812.2k](/packages/erag-laravel-lang-sync-inertia)

PHPackages © 2026

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