Laravel Localization package that auto generate json locale files
mahmoud217tr/auto-files-localizer is a Laravel package for laravel localization package that auto generate json locale files.
It currently has 1 GitHub stars and 60 downloads on Packagist (latest version 1.1.0).
Install it with composer require mahmoud217tr/auto-files-localizer.
Discover more Laravel packages by mahmoud217tr
or browse all Laravel packages to compare alternatives.
Last updated
Easy and Efficient Localiztion
A Laravel Localization package that auto generate json locale files
You can install the package via composer:
composer require mahmoud217tr/auto-files-localizer
To publish the package configuration file config/auto-localizer.php use the following command:
php artisan vendor:publish --tag="auto-files-localizer-config"
It will automatically generate the locale .json file where the localized new words are sorted alphabetically.
There are 2 modes for the package
In this mode the translations will be generated dynamically (On Request) which means on upon calling the translation function the package will dynamically detect the current language and add the translations to the corresponding JSON file.
Note that this mode shouldn't work on production for performance purposes, but if you want to change this behavior via the configuration file.
This mode is not recommended using with vite development mode. If you want to use it please build your assets first using npm run build then activate the auto translation mode. OTHERWISE YOUR APP WILL STUCK IN RELOAD LOOP
To activate the dynamic mode on non-production environment just add the following line to the .env file:
AUTO_LOCALIZER_ENABLED=true
And that's about it the autotranslator will add transaltions to there files sorted alphabetically.
To deactivate the dynamic mode just set the previous value to false.
This mode have the following configurations:
'dynamic' => [
# Controls if the dynamic mode should work or not on non-production environments
'enabled' => (bool) env('AUTO_LOCALIZER_ENABLED', false),
# Controls if the dynamic mode should work or on production environment (compined with the previous option)
'production' => false,
],
In this mode the translations will be extracted automatically from views or php files detecting translation functions adding the translations to the corresponding JSON file.
To extract the translations for a specific locale (ar for example) run the following command:
php artisan localizer:extract ar
The previous command will translate all non-localized phrases and all ar-localized phrases only.
This mode have the following configurations:
'extraction' => [
# The directories where the translation scanner will scan
'directories' => [
'resources/views',
],
# The file patterns that the translation scanner will scan
'patterns' => [
'*.php'
],
# The translation functions or directives that scanner will detect (you should add your custom functions here)
'functions' => [
'__',
'trans',
'@lang',
],
],
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.