This package is built on top of PHP JSON tongue to enable the usage of multiple JSON files per locale on Laravel.
Starting with Laravel docs:
Translation strings may be defined within JSON files that are placed within the lang directory. When taking this approach, each language supported by your application would have a corresponding JSON file within this directory. This approach is recommended for applications that have a large number of translatable strings.
Intuitively, many developers wonder why isn't it possible to have each language supported by their application have multiple corresponding JSON files. Multiple JSON files allows grouping strings by topic, and keeping the files small and clear.
Install the package via composer:
composer require elaborate-code/laravel-json-tongue
- PHP 8.0 or higher.
File structure example:
The JSON files can co-exist with the PHP files without any conflicts!
This command loads all the JSON files from /<locale>
folders within the /lang
folder and merge them per locale in new JSON files.
php artisan json-tongue:merge
Options:
Option | Description |
---|---|
-F|--force |
Removes JSON files that already exist in the root of the lang folder without asking |
JSON files that already exist in the root of the
lang
folder, can be old JSON files previously generated by the command, or files that you have created manually and populated manually.
⚠️ In the second case be careful before instructing the command to remove existing JSON files!
Before merging :
lang
┣ 📂es
┃ ┣ 📜animals.json
┃ ┣ 📜greetings.json
┃ ┗ 📜jobs.json
┗ 📂fr
┣ 📜animals.json
┣ 📜greetings.json
┗ 📜jobs.json
After merging:
lang
┣ 📂es
┃ ┣ 📜animals.json
┃ ┣ 📜greetings.json
┃ ┗ 📜jobs.json
┣ 📂fr
┃ ┣ 📜animals.json
┃ ┣ 📜greetings.json
┃ ┗ 📜jobs.json
┣ 📜es.json ⭐ Usable by Laravel
┗ 📜fr.json ⭐ Usable by Laravel
./vendor/bin/pest
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Help needed to add a watch command that refreshes the output JSON files with new translations added on the locale folders.
The MIT License (MIT). Please see License File for more information.