anastalal / laravel-translation-importer
A Laravel Package to synchronise translation keys. This package simplifies the process of maintaining translations, especially when new keys are introduced during development.
Requires
- php: ^8.2
- illuminate/support: ^11.0
Requires (Dev)
- orchestra/testbench: ^6.0|^8.0|^9.5
- phpunit/phpunit: ^9.0|^10.0|^11.0
This package is auto-updated.
Last update: 2024-11-06 19:54:39 UTC
README
Introduction
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.
Features
- 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.
Installation
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"
Usage
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.
Sync Missing Translation Keys
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
Sync Translations
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
Configuration
Once you’ve published the configuration, you can customize the package’s behavior by modifying the config file located at:
config/translation-importer.php
Testing
To ensure the package works as expected, you can run the following tests:
composer test
Contributing
Contributions are welcome!
License
The Laravel Translation Importer is open-sourced software licensed under the MIT license.