https://github.com/elaborate-code/laravel-json-tongue
📦🌐 Use multiple JSON files per locale on Laravel
https://github.com/elaborate-code/laravel-json-tongue
internationalization languages laravel locale localization package php8 translation
Last synced: about 2 months ago
JSON representation
📦🌐 Use multiple JSON files per locale on Laravel
- Host: GitHub
- URL: https://github.com/elaborate-code/laravel-json-tongue
- Owner: elaborate-code
- License: mit
- Created: 2022-10-06T20:15:21.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-26T22:06:02.000Z (about 3 years ago)
- Last Synced: 2025-05-02T19:05:40.654Z (about 1 year ago)
- Topics: internationalization, languages, laravel, locale, localization, package, php8, translation
- Language: PHP
- Homepage: https://packagist.org/packages/elaborate-code/laravel-json-tongue
- Size: 50.8 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Laravel JSON tongue
[](https://packagist.org/packages/elaborate-code/laravel-json-tongue)
[](https://github.com/elaborate-code/laravel-json-tongue/actions?query=workflow%3Arun-tests+branch%3Amain)
[](https://github.com/elaborate-code/laravel-json-tongue/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[](https://packagist.org/packages/elaborate-code/laravel-json-tongue)


This package is built on top of [PHP JSON tongue](https://github.com/elaborate-code/php-json-tongue) to enable the usage of multiple JSON files per locale on Laravel.
## Introduction
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.
[Read more...](https://laravel.com/docs/9.x/localization#using-translation-strings-as-keys)
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.
## Installation
Install the package via composer:
```bash
composer require elaborate-code/laravel-json-tongue
```
### Requirements
- PHP 8.0 or higher.
## Usage
File structure example:

> The JSON files can co-exist with the PHP files without any conflicts!
### The merge command
This command loads all the JSON files from `/` folders within the `/lang` folder and merge them per **locale** in new JSON files.
```bash
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!
#### Example
Before merging :
```txt
lang
┣ 📂es
┃ ┣ 📜animals.json
┃ ┣ 📜greetings.json
┃ ┗ 📜jobs.json
┗ 📂fr
┣ 📜animals.json
┣ 📜greetings.json
┗ 📜jobs.json
```
After merging:
```txt
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
```
## Testing
```bash
./vendor/bin/pest
```
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
Help needed to add a watch command that refreshes the output JSON files with new translations added on the locale folders.
## Credits
- [medilies](https://github.com/medilies)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.