Download the PHP package kanekescom/laravel-lingo without Composer
On this page you can find all versions of the php package kanekescom/laravel-lingo. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kanekescom/laravel-lingo
More information about kanekescom/laravel-lingo
Files in kanekescom/laravel-lingo
Package laravel-lingo
Short Description Laravel package to manage, sync, and analyze JSON translation files
License MIT
Homepage https://github.com/kanekescom/laravel-lingo
Informations about the package laravel-lingo
Laravel Lingo
Laravel package to manage, sync, and analyze JSON translation files.
Features
- ๐ Scan for translation keys in your codebase
- ๐ Statistics on translation progress
- ๐ Sync translations with source files
- ๐งน Clean and sort translation files
- ๐ง Artisan commands for CLI management
How It Works
Key Concepts
Translation File Format
Lingo works with Laravel's JSON translation files (not PHP array files). These files are located at lang/{locale}.json:
Translation Status Detection
Lingo determines whether an item is translated or not by comparing the key and value:
- โ
Translated โ key โ value (e.g.,
"Hello": "Halo") - โ ๏ธ Untranslated โ key = value (e.g.,
"Save": "Save") - ๐๏ธ Empty โ value is empty string (e.g.,
"Hello": "")
Duplicate Detection
Since PHP automatically overwrites duplicate keys during json_decode(), Lingo uses regex on raw JSON content to detect duplicates before parsing:
How Source Scanning Works
The lingo:sync command and sync() method work by scanning your source code to find translation keys. The scanning process uses 4 regex patterns to detect Laravel translation function calls:
| Pattern | Detected Examples |
|---|---|
__('...') |
__('Hello'), __("Welcome") |
trans('...') |
trans('Save'), trans("Cancel") |
@lang('...') |
@lang('Submit') (Blade directive) |
Lang::get('...') |
Lang::get('Delete') |
Scanning process:
- Resolve path โ Relative paths are resolved via
base_path(), absolute paths are used directly if they exist - Recursive scan โ For directories, all
.phpfiles are scanned recursively usingRecursiveIteratorIterator - Extract keys โ Each file's content is matched against the 4 regex patterns above
- Deduplicate โ All found keys are deduplicated using
array_unique()
Sync Workflow
lingo:sync is the most powerful command. Here's how it works:
Steps:
- Scan all given paths (default:
resources/views) - Collect all translation keys found in source code
- Compare with existing keys in the JSON file
- Add missing keys (value = key, so they are easily identified as untranslated)
- Remove keys that are no longer used in source code
- Save the updated JSON file (sorted alphabetically)
File Path Resolution
All commands accept either a locale code or a direct file path:
File search order:
base_path("lang/{locale}.json")lang_path("{locale}.json")resource_path("lang/{locale}.json")
Installation
Usage
Artisan Commands
All commands accept an optional locale argument. If omitted, defaults to config('app.locale').
Note: All paths are relative to your application root. Both files and directories are supported.
Programmatic Usage
Available Methods
Entry Points
| Method | Description |
|---|---|
Lingo::locale('id') |
Load by locale โ lang/id.json |
Lingo::fromFile($path) |
Load from custom file path |
Lingo::make($arr, $locale) |
Create from array with optional locale |
lingo($arr, 'id') |
Helper: create from array with locale |
Chainable Methods
| Method | Description |
|---|---|
to($locale) |
Set target locale for save() |
sync($paths) |
Sync with source files (accepts string, array, or null for default views). Supports files and directories. |
sortKeys($asc) |
Sort keys alphabetically (default: A-Z) |
clean() |
Remove empty values and sort keys |
merge($arr) |
Merge with another array |
add($keys) |
Add keys if not present |
remove($keys) |
Keep only keys in list |
removeEmpty() |
Remove empty values |
onlyUntranslated() |
Filter to untranslated items |
onlyTranslated() |
Filter to translated items |
transform($fn) |
Transform translations with callback |
tap($fn) |
Inspect translations without modifying |
Output Methods
| Method | Description |
|---|---|
save($path) |
Save to file (path optional) |
toJson() |
Export as JSON string |
get() |
Get translations array |
toArray() |
Alias for get() |
stats() |
Get translation statistics |
count() |
Get number of translations |
isEmpty() |
Check if translations empty |
isNotEmpty() |
Check if translations not empty |
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Achmad Hadi Kurnia
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-lingo with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^11.0||^12.0