Easy and Efficient Localiztion
A Laravel Localization package that auto generate json locale files
- Supports Laravel (8.X, 9.X, 10.X, 11.X).
- 2 Modes (Dynamic Mode, Extraction Mode).
- Fast and reliable.
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 usingnpm 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.