netcore / translations
Laravel translations stored in database for easy CRUD
Installs: 3 672
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 5
Forks: 2
Open Issues: 0
Requires
- illuminate/cache: ^5.3
- illuminate/console: ^5.3
- illuminate/database: ^5.3
- illuminate/routing: ^5.3
- illuminate/support: ^5.3
- illuminate/translation: ^5.3
- rmccue/requests: ^1.7
Requires (Dev)
- phpunit/phpunit: ^6.0
- dev-master
- v1.0.50
- v1.0.49
- v1.0.48
- v1.0.47
- v1.0.46
- v1.0.45
- v1.0.44
- v1.0.43
- v1.0.42
- v1.0.41
- v1.0.40
- v1.0.39
- v1.0.38
- v1.0.37
- v1.0.36
- v1.0.35
- v1.0.34
- v1.0.33
- v1.0.32
- v1.0.31
- v1.0.30
- v1.0.29
- v1.0.28
- v1.0.27
- v1.0.26
- v1.0.25
- v1.0.24
- v1.0.23
- v1.0.22
- v1.0.21
- v1.0.20
- v1.0.19
- v1.0.18
- v1.0.17
- v1.0.16
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
This package is not auto-updated.
Last update: 2024-11-01 23:17:02 UTC
README
By default Laravel translations are kept in language files under resources folder. This makes standart CRUD operations very cumbersome, so we decided it would be better to store all translations in a database. Benefits of this are:
- Easy CRUD operations and nice UI for admin
- Avoid GIT conflicts if lang files are edited in filesystem
- Performance is still great. Database is accessed only once and then translations are cached
- Import/export translations as Excel files for storing on Google Spreadsheets or locally
Installation
Require this package with composer:
composer require netcore/translations --dev
Add our service provider to "providers" array in config/app.php:
\Netcore\Translator\ServiceProvider::class
Run migrations to create "translations" and "languages" tables:
php artisan migrate
Add routes to RouteServiceProvider.php. Choose middleware that will allow admins only to edit translations:
Route::group([
'middleware' => ['web', 'isAdmin'],
'namespace' => null,
'prefix' => 'admin',
'as' => 'admin.'
], function (Router $router) {
\Netcore\Translator\Router::adminRoutes($router);
});
Package uses cache tags. You can check out laravel documentation to find out more about cache tags . https://laravel.com/docs/5.4/cache#cache-tags
One of the options is to use redis.
First of all, install redis package by running this composer command.
composer require predis/predis
Then you need to change your cache driver in .env file to redis like this
CACHE_DRIVER=redis
Publish config files for defining your Admin layout to extend, translating ACP UI and more:
php artisan vendor:publish --tag=config
How to download translations from live server to development
We often want to get exact copy of translations from live server to either development or our local server. In order to do that, we must expose API routes in RouteServiceProvider.php:
Route::group([
'middleware' => ['api'],
'namespace' => null,
'prefix' => 'api',
'as' => 'api.'
], function ($router) {
Router::apiRoutes($router);
});
After that, point this .env variable to your live server:
NETCORE_TRANSLATIONS_DOWNLOAD_FROM=https://project.eu/api/translations/index
And then run php artisan translations:download
on your development or local machine.
Is it battle tested?
This package has already been battle tested in numerous Netcore projects. We finally got tired of copying the code over to new projects, so code has been extracted to installable package.
Future plans
- Unit tests
- Different branches for different versions of Laravel
- Rewrite ACP UI with Vue.js