The Laravel Translation Importer package is a simple and powerful solution to manage your Laravel application's translation keys efficiently. It scans your project for translation functions (__()
and trans()
) and automatically updates the translation files located in the resources/lang
directory.
This package simplifies the process of maintaining translations, especially when new keys are introduced during development. It helps you avoid missing translation keys by automating the synchronization between your project and language files.
- Manual scanning: The package provides commands to scan your project for translation keys inside
__()
andtrans()
functions. You can run these commands to update your translation files as needed. - File generation: It generates and updates translation files in
resources/lang
. - CLI Commands: Use artisan commands to sync missing keys or update existing ones.
- Supports Multiple Languages: The package is compatible with multi-language projects and works seamlessly across different locales.
You can install the package via composer:
composer require anastalal/laravel-translation-importer
After installing, you need to publish the configuration file using:
php artisan vendor:publish --provider="Anastalal\LaravelTranslationImporter\TranslationImporterServiceProvider"
Important Note: Before using the package, you must manually create the necessary language folders and files in the
resources/lang
directory. For example:
resources/lang/
├── en/
│ └── messages.php
├── ar/
│ └── messages.php
├── en.json
└── ar.json
You need to ensure that directories and files for the languages that you want are in place, as the package does not generate them automatically.
The following command scans your project files for any missing translation keys and adds them to the respective language files in the resources/lang folder:
php artisan translation-importer:sync-missing-translation-keys
To ensure that all translations are up-to-date, use the sync command. This will compare existing translations and update them as needed:
php artisan translation-importer:sync-translations
Once you’ve published the configuration, you can customize the package’s behavior by modifying the config file located at:
config/translation-importer.php
To ensure the package works as expected, you can run the following tests:
composer test
Contributions are welcome!
The Laravel Translation Importer is open-sourced software licensed under the MIT license.