Download the PHP package webo3/laravel-translator without Composer
On this page you can find all versions of the php package webo3/laravel-translator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download webo3/laravel-translator
More information about webo3/laravel-translator
Files in webo3/laravel-translator
Package laravel-translator
Short Description This package add artisan commands to scan/export/import translations.
License MIT
Homepage https://www.webo3.com
Informations about the package laravel-translator
Laravel Translator
A Laravel package that provides artisan commands to scan, export, import and auto-translate translation strings. It extracts translation keys from your source code, manages JSON language files, supports CSV and XLIFF workflows for working with translators, and can automatically translate using the Google Translate API.
Supported translation functions
| Function | File types | Example |
|---|---|---|
__() |
PHP, JS, TS, Vue | __('Hello world') |
Lang::get() |
PHP | Lang::get('messages.welcome') |
@lang() |
PHP (Blade) | @lang('Please login') |
$t() |
JS, TS, Vue | $t('Vue key') |
.t() |
JS, TS, Vue | i18n.t('My key') |
Quote handling
- Single quotes:
__('key') - Double quotes:
__("key") - Escaped quotes:
__('It\'s a test')correctly extractsIt's a test - Backtick template literals (JS/TS/Vue only):
__(`multi-line key`) - Backticks are ignored in PHP files (where they are the shell execution operator)
Installation
Package auto-discovery is enabled for Laravel >= 5.5. For older versions, register the provider manually in config/app.php:
Configuration
Publish the configuration file to specify which languages to manage:
This creates config/webo3-translator.php with the following options:
Usage
1. Scan and extract translations
Scans *.php, *.js, *.ts and *.vue files in the configured scan_paths for translation function calls. Extracts unique keys and creates/updates a JSON file for each configured language.
- New keys are added with the key itself as the default value
- Existing translations are preserved
- Keys are sorted alphabetically
- Comments (
//and/* */) are stripped before scanning, but//inside strings (e.g. URLs) is preserved
Clean unused keys
Add the --clean option to detect and remove translation keys that are no longer used in your source files:
This will scan your code, then compare existing keys in each language JSON file against the keys found in source. Unused keys are listed in a table and you are prompted for confirmation before they are removed.
2. Export translations
Reads all language JSON files and exports them in the configured format.
CSV format (default)
Exports a single translations.csv file with a UTF-8 BOM for Excel compatibility:
| key | en | fr |
|---|---|---|
| Hello world | Hello world | Bonjour le monde |
| Goodbye | Goodbye | Au revoir |
Untranslated values (where the value equals the key) appear as empty cells.
XLIFF format
Set 'format' => 'xliff' in your config. Exports one XLIFF 1.2 file per target language (e.g. translations-fr.xlf). The first language in your languages array is used as the source language.
XLIFF is the industry standard format supported by professional translation tools (SDL Trados, memoQ, Phrase, Crowdin, etc.).
3. Import translations
Reads the exported file(s) and merges the translated values back into the JSON language files.
- New keys are added
- Existing translations are updated if the file has a different value
- Empty values default to the key itself
- Keys are sorted alphabetically after import
- The import format is determined by the
formatconfig option (same as export)
4. Auto-translate with an API
Automatically translates untranslated keys using a translation API and saves the results directly to your JSON language files.
First, install the Google Translate package:
Then run:
This translates all untranslated keys (where value equals the key) from the source language to every other configured language.
Options
| Option | Description |
|---|---|
--lang=fr,es |
Only translate specific target languages |
--force |
Re-translate keys that already have translations |
--driver=google_free |
Override the translation driver from config |
--batch-size=50 |
Number of strings per API call (default: 50) |
Placeholder preservation
The command automatically preserves Laravel and Vue placeholders during translation:
- Laravel style:
:name,:count,:attribute - Brace style:
{name},{count},{item}
These are masked before sending to the API and restored in the translated result.
Case deduplication
Keys that differ only in letter case (e.g. "Hello", "hello", "HELLO") are deduplicated into a single API call. The translated result is then adjusted to match each variant's casing (uppercase, lowercase, title case).
Configuration
Two config keys control auto-translation:
Custom drivers
You can register your own translation driver by binding it in the service container:
Then use it with --driver=my_driver or set 'translation_driver' => 'my_driver' in config.
Typical workflow
- Write code using
__('key'),$t('key'), etc. - Run
php artisan translations:scanto extract all keys - Either:
- Auto-translate: Run
php artisan translations:translateto translate via API - Manual workflow: Export → send to translator → import:
php artisan translations:export- Send the file(s) to your translator
php artisan translations:import
- Auto-translate: Run
Using translations in Vue
Install the vue-i18n package:
Set up vue-i18n in your app.js:
Then use $t() or i18n.t() in your templates:
Testing
License
MIT