translators-hive/laravel-autotranslate

Translators Hive Laravel Autotranslate Package

Maintainers

Package info

github.com/Translators-Hive/laravel-autotranslate

pkg:composer/translators-hive/laravel-autotranslate

Transparency log

Statistics

Installs: 31

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v2.0.1 2026-07-15 13:58 UTC

This package is auto-updated.

Last update: 2026-07-15 14:00:33 UTC


README

Automatically extract and machine-translate all untranslated strings in your Laravel project with a single Artisan command. Supports PHP lang files, JSON translation files, Eloquent model attributes, and JavaScript/Vue/React source files.

Requirements

  • PHP 8.0+
  • Laravel 8+

Installation

composer require translators-hive/laravel-autotranslate

Publish the config file:

php artisan vendor:publish --provider="TranslatorsHive\LaravelAutoTranslate\ServiceProvider" --tag="config"

Configuration

Add your translators-hive.com credentials to .env:

TranslatorsHiveEmail=your@email.com
TranslatorsHivePassword=yourpassword

Commands

th:translate — translate PHP & JSON lang files

Scans your source files, extracts translation strings, and sends untranslated ones to the API.

# Translate to specific locales
php artisan th:translate es,bg,de,fr

# Use app.locale (or auto-detect from routing package config)
php artisan th:translate

The command creates:

  • resources/lang/{locale}.json for plain-string keys ("Welcome back")
  • resources/lang/{locale}/auth.php, validation.php, etc. for dot-notation keys (auth.failed)

Already-translated strings are never overwritten.

th:translate-models — translate Eloquent model attributes

Translates model attributes stored via spatie/laravel-translatable or astrotomic/laravel-translatable.

php artisan th:translate-models es,de

# Uses app.locale as source and translates to all given locales
php artisan th:translate-models fr

The command scans app/Models/ (configurable) for models using a translatable trait, queries for records with missing locale values, and writes the translations back to the database.

Package Integrations

The plugin auto-detects installed packages and adapts its behaviour — no manual configuration required.

mcamara/laravel-localization · codezero/laravel-localized-routes

When either package is installed, th:translate reads its supportedLocales / supported_locales config and uses that as the locale list automatically. You no longer need to pass locale codes as arguments.

laravel-lang/lang

When installed, auth.php, validation.php, pagination.php, and passwords.php are excluded from machine translation. These files contain human-vetted community translations and should not be overwritten.

You can extend the exclude list in the config:

// config/translators-hive-autotranslate.php
'exclude_files' => ['custom-file'],

spatie/laravel-translation-loader

When installed, the plugin automatically switches to database storage (language_lines table) for both reading existing translations and writing new ones. Set storage in the config to override:

'storage' => 'auto',     // default — auto-detect
'storage' => 'database', // always use DB
'storage' => 'file',     // always use lang/ files

spatie/laravel-translatable · astrotomic/laravel-translatable

Supported via the th:translate-models command. The scanner detects models automatically based on trait usage and the $translatable / $translatedAttributes property.

JavaScript / Vue / React Scanning

Disabled by default. Enable it for Inertia.js or mixed Laravel+Vue/React projects:

// config/translators-hive-autotranslate.php
'js' => [
    'enabled'   => true,
    'dirs'      => ['resources/js'],
    'patterns'  => ['*.js', '*.jsx', '*.ts', '*.tsx', '*.vue'],
    'functions' => ['$t', 't', '__', 'trans'],
],

Scanning Configuration

Control which files and functions are scanned:

'search' => [
    'dirs'      => ['resources', 'app'],
    'patterns'  => ['*.php'],
    'functions' => ['__', 'trans', 'trans_choice', 'choice', '@lang', '@choice'],
],

Add custom helper functions to functions if your project defines its own translation wrappers.

Other Options

// Sort keys alphabetically in generated files
'sort' => true,

// API batch size (max 100; 80 is the safe default)
'batch_size' => 80,

// Retry attempts on 503/504 responses
'retry_attempts' => 3,

// Base delay between retries in milliseconds (multiplied by attempt number)
'retry_delay_ms' => 1000,

// Directories scanned by th:translate-models
'models' => [
    'dirs' => ['app/Models', 'app'],
],

Changelog

See CHANGELOG for recent changes.

Support

admin@translators-hive.com · translators-hive.com