dlogon / translation-manager
This is my package translation-manager
Requires
- php: ^8.1
- dlogon/tailwind-alerts: ^0.2
- illuminate/contracts: ^9.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.8
- nunomaduro/collision: ^6.0
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpunit/phpunit: ^9.5
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2024-11-07 00:53:20 UTC
README
Manage your translations in your laravel proyect with a web interface.
This package has been inspired by barryvdh/laravel-translation-manager
Installation
You can install the package via composer:
composer require dlogon/translation-manager
You can run the migrations and optional publish the migrations with:
php artisan vendor:publish --provider="Dlogon\TranslationManager\TranslationManagerServiceProvider" --tag="migrations" php artisan migrate
You can publish the config file with:
php artisan vendor:publish --provider="Dlogon\TranslationManager\TranslationManagerServiceProvider" --tag="config"
Optionally, you can publish the views using
php artisan vendor:publish --provider="Dlogon\TranslationManager\TranslationManagerServiceProvider" --tag="views"
Usage
To access the web manager, access to the url "yourproject"/translations, if you want to change the route prefix of the manager, publish the config file (translation-manager.php) and change "prefix" inside the "route" array, therefore, if you are not using auth, comment the "auth" middleware inside the route array
'route' => [ 'prefix' => 'translations', 'middleware' => [ 'web', 'auth', ], ],
This is that you will see when enter to the manager
When you add a new Lang, you'll see the lang in the bellow section (ADD NEW KEY) and in the table on the bottom
Then, you should add a group in the Groups tab, groups are intended to create diferent files if you work with the "php array" aproach, or for "enhance" the visual presentation if you use the "json" aproach.
Now, you can add a key, with a value for every lang that you have been created. when you press add, you will see the added key in the bottom table, if you do not see the key, ensure that you select the group where you store the key in the above dropdown.
if you want to change any translation, just click the translation and you will see an input to put the new translation, if you click the Ok button, you will see a notifications saying that the translation updated successfully
Model translations
Maybe you noticed the Model translations tab, here, you can generate a group for every model in your app, and this will generate a key for every column in you model.
For example, if we have a Post model, and we already run the migration with some columns.
If you want to avoid some columns, you can add it into the config file, there are a default ignored columns of the User model, and there are a default columns ignored from all models
'ignore_columns' => [ "id", "created_at", "updated_at", "deleted_at" ], 'ignore_model_columns' => [ "users" => [ "email_verified_at", "remember_token" ] ],
Generating the translation files
Once you are ready and you have created your translations, is time to create the translations files, above all you will see the big orange button Generate translations, below you will see a radio where you can select the aproach.
If you select the php aproach, your translation files will have the structure
rootapp/<your lang folder>/<lang1>/
group1.php
group2.php
rootapp/<your lang folder>/<lang2>/
group1.php
group2.php
If you select the JSON aproach, you will see a property in your generated json, this property has the structure
"//GROUP<group-name>" = "///////////////GROUP-<group-name>/////////////////////"
for example:
en.json
{ "\/\/GROUPapp": "\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/GROUP-app\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/", "Welcome": "Welcome", "\/\/GROUPlanding": "\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/GROUP-landing\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/", "\/\/GROUPPost": "\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/GROUP-Post\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/", "autor_name": "Autor Name", "title": "Title", "\/\/GROUPUser": "\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/GROUP-User\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/", "email": "", "name": "", }
es.json
{ "\/\/GROUPapp": "\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/GROUP-app\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/", "Welcome": "Bienvenido", "\/\/GROUPlanding": "\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/GROUP-landing\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/", "\/\/GROUPPost": "\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/GROUP-Post\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/", "autor_name": "Nombre del autor", "title": "Titulo", "\/\/GROUPUser": "\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/GROUP-User\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/", "name": " ", "email": " " }
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.
TODO
- Read and store lang files in database
- Filter keys
- Read lang and add to database on install package