Download the PHP package elegantly/laravel-translator without Composer
On this page you can find all versions of the php package elegantly/laravel-translator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download elegantly/laravel-translator
More information about elegantly/laravel-translator
Files in elegantly/laravel-translator
Package laravel-translator
Short Description All on one translations management for Laravel
License MIT
Homepage https://github.com/ElegantEngineeringTech/laravel-translator
Informations about the package laravel-translator
All-in-One Translations Manager for Laravel
Easily manage all your Laravel translation strings with powerful features:
- Translate strings into other languages using DeepL, OpenAI, or custom services.
- Proofread translations to fix grammar and syntax automatically (via OpenAI or custom services).
- Find missing translation strings across locales.
- Detect unused translation keys in your codebase.
- Sort translations in natural order.
- Import & Export translations in a CSV file.
Try Laratranslate – A Powerful UI for Managing Translations
Table of Contents
- How does it work?
- Installation
- Configuring the Driver
- Configuring the Locales
- Automatic Detection
- Manual Setup
- Configuring the Code Scanner
- Requirements
- Included Paths
- Excluded Paths
- Ignored Translation Keys
- Sorting and Formatting
- CLI Commands
- Using Code
- Automatic Translation
- Configuring OpenAI
- Configuring DeepL
- CLI Translation
- Programmatic Translation
- Proofreading Translations
- CLI Proofreading
- Programmatic Proofreading
- Identifying Untranslated Translations
- CLI Usage
- Programmatic Usage
- Detecting Missing Translations
- CLI Usage
- Programmatic Usage
- Detecting Dead Translations
- CLI Usage
- Programmatic Usage
- Export to a CSV
- CLI Usage
- Programmatic Usage
- Import from a CSV
- CLI Usage
- Programmatic Usage
How does it work?
This package will directly modify your translation files like /lang/en/messages.php
or /lang/fr.json
for example.
Both PHP
and JSON
files are supported.
Advanced features like dead translations detection will scan your entire codebase to find unused translation strings.
Installation
Install the package via Composer:
Add the following line to your .gitignore
file:
Publish the configuration file:
Configuring the Driver
This package uses a driver-based architecture. By default, it supports two standard drivers: PHP and JSON.
- Use the
PHP
driver if you store your translation strings in.php
files, such as/lang/en/message.php
. - Use the
JSON
driver if you store your translation strings in.json
files, such as/lang/fr.json
.
You can also create custom drivers for alternative storage methods, such as a database.
Set the default driver in the configuration file:
[!NOTE] All features are supported in both the PHP and JSON drivers.
Configuring the Locales
Automatic Detection
By default, this package will attempt to determine the locales defined in your application by scanning your lang
directory.
You can customize this behavior in the configuration file.
Manual Setup
To set the locales manually, use the following configuration:
Configuring the Code Scanner
Service: searchcode
.
Features:
- Detecting Missing Translations
- Detecting Dead Translations
Both the detection of dead and missing translations rely on scanning your code.
- Missing translations are keys found in your codebase but missing in translation files.
- Dead translations are keys defined in your translation files but unused in your codebase.
Requirements
At the moment, this package can only scan the following files:
.php
.blade.php
[!NOTE] If you use a React or Vue frontend, it would not be able to scan those files, making this feature irrelevant.
The default detector uses nikic/php-parser
to scan all your .php
files, including the Blade ones.
In order to be able to detect your keys, you will have to use one of the following Laravel function:
__(...)
,trans(...)
trans_choice(...)
\Illuminate\Support\Facades\Lang::get(...)
\Illuminate\Support\Facades\Lang::has(...)
\Illuminate\Support\Facades\Lang::hasForLocale(...)
\Illuminate\Support\Facades\Lang::choice(...)
app('translator')->get(...)
app('translator')->has(...)
app('translator')->hasForLocale(...)
app('translator')->choice(...)
Or one of the following Laravel Blade directive:
@lang(...)
Here is some example of do's and don'ts:
Included Paths
Specify paths to scan for translation keys. By default, both .php
and .blade.php
files are supported.
Excluded Paths
Exclude irrelevant paths for optimized scanning, such as test files or unrelated directories.
Ignored Translation Keys
Ignore specific translation keys:
Sorting and Formatting
CLI Commands
Sort translations with the default driver:
Specify a driver for sorting:
Using Code
Sort translations programmatically with the default driver:
Specify a driver:
Automatic Translation
Service: translate
.
Before translating, configure a translation service. The package supports:
- OpenAI
- DeepL
Custom translation services can also be implemented.
Configuring OpenAI
Define your OpenAI credentials in the configuration file or via environment variables:
Configuring DeepL
Add your DeepL API key to the configuration file or environment variables:
CLI Translation
Display all keys defined in the source locale (English) but not translated in the target (French):
Translate untranslated English strings into French:
Translate using a specific driver:
Add a new locale (French) with their translations from a source (English):
Programmatic Translation
Translate translations programmatically with the default driver:
Specify a driver for translation:
Proofreading Translations
Service: proofread
.
Proofreading corrects the grammar and syntax of your translation strings.
Currently, OpenAI is the only built-in service, but custom services can be implemented.
To configure OpenAI, see Configuring OpenAI.
CLI Proofreading
Proofread all strings in the target locale (English).
Programmatic Proofreading
Proofread translations with the default driver:
Specify a driver:
Identifying Untranslated Translations
Find keys defined in one locale but missing in another.
CLI Usage
Display all keys defined in the source locale (English) but not in the target locale (French).
Programmatic Usage
Detecting Missing Translations
Service: searchcode
.
Configuration: Configuring the Code Scanner
Missing translations are keys found in your codebase but missing in translation files.
CLI Usage
Find keys defined in your codebase but missing in your locale (English) using your default driver:
Specify a driver:
Add the missing keys to your driver:
Programmatic Usage
Detecting Dead Translations
Service: searchcode
.
Configuration: Configuring the Code Scanner
Dead translations are keys defined in your locale (English) but unused in your codebase.
CLI Usage
Programmatic Usage
Export to a CSV
Service: exporter
Export all your translation strings to a CSV file in the following format:
Key | English | French |
---|---|---|
messages.auth.login | Login | Connexion |
CLI Usage
Programmatic Usage
Import from a CSV
Service: exporter
Import translation strings from a CSV file. Ensure your CSV follows the format below:
Key | English | French |
---|---|---|
messages.auth.login | Login | Connexion |
CLI Usage
Programmatic Usage
Testing
Run tests using:
Changelog
See the CHANGELOG for recent updates.
Contributing
Check the CONTRIBUTING guide for details.
Security Vulnerabilities
Report security vulnerabilities via GitHub or email.
Credits
- Quentin Gabriele
- All Contributors
License
This package is licensed under the MIT License. See the License File for more details.
All versions of laravel-translator with dependencies
deeplcom/deepl-php Version ^1.7
illuminate/contracts Version ^10.0||^11.0||^12.0
nikic/php-parser Version ^5.1
openai-php/laravel Version ^0.11
spatie/laravel-package-tools Version ^1.16
spatie/simple-excel Version ^3.7
symfony/finder Version ^6.0||^7.0
symfony/intl Version ^7.2