Package Data | |
---|---|
Maintainer Username: | netcorelv |
Maintainer Contact: | kristerskz@gmail.com (Kristers Zariņš) |
Package Create Date: | 2017-04-17 |
Package Last Update: | 2018-09-05 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-17 03:02:45 |
Package Statistics | |
---|---|
Total Downloads: | 3,673 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 3 |
Total Watchers: | 5 |
Total Forks: | 2 |
Total Open Issues: | 0 |
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:
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
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.
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.