Change standard Laravel file-based translation to DB.
Require this package in your composer.json and run composer update:, (*2)
"xdroidteam/translation": "1.5.*"
or run, (*3)
composer require xdroidteam/translation
directly., (*4)
After updating composer, add the ServiceProvider to the providers array in config/app.php, (*5)
'XdroidTeam\Translation\TranslationServiceProvider',
Deploy migration and config file., (*6)
php artisan vendor:publish --tag=xdroidteam-translation
You need to run the migrations for this package., (*7)
php artisan migrate
Add following line to your .env file:, (*8)
LANGUAGES=en,hu,de
Import existing language files to DB:, (*9)
php artisan translations:import
or import with override existing records:, (*10)
php artisan translations:import --overwrite
Routes are added in the ServiceProvider, available at http://yourdomain.com/translations
, (*11)
You can change the route prefix in the deployed config file config/xdroidteam-translation.php
. Also you can modify the middleware or exclude translation groups (excluded groups will not appear on the GUI). See the example below., (*12)
<?php return array( 'route' => [ 'prefix' => 'custom-translations-route', 'middleware' => [ 'web', 'auth', 'custom middleware', ], ], 'exclude_groups' => ['auth', 'base'], 'translation_model' => '\App\Models\Translation', );
You can use other Translation model, to overwrite methods. For example:, (*13)
<?php namespace App\Models; use XdroidTeam\Translation\Translation as XdroidTranslation; class Translation extends XdroidTranslation { public static function getLanguages(){ // original: // return explode(',', env('LANGUAGES')); //custom: return ['en', 'hu']; } }
You can export your db to a .CSV file, with call this function:, (*14)
XdroidTeam\Translation::exportToCSV('path/to/file');