-
Notifications
You must be signed in to change notification settings - Fork 84
Installation
-
Require this package in your composer.json and run composer update (or run
composer require vsch/laravel-translation-manager:*
directly):"require": { "vsch/laravel-translation-manager": "~2.0" }
- if you are not going to be customizing the web interface it is highly recommended that you add automatic asset publishing for this package after upgrade in your project's composer.json:
"scripts": { "post-update-cmd": [ ... other stuff ... "php artisan vendor:publish --provider=\"Vsch\\TranslationManager\\ManagerServiceProvider\" --tag=public", ... other stuff ... ] },
Otherwise a future update, that needs new assets, will not work properly. composer does not run post-update scripts of packages.
Here is a full scripts section of a standard Laravel 5.1 project composer.json should look like after the change.
{ "scripts": { "post-install-cmd": [ "php artisan clear-compiled", "php artisan optimize" ], "pre-update-cmd": [ "php artisan clear-compiled" ], "post-update-cmd": [ "php artisan ide-helper:generate", "php artisan vendor:publish --provider=\"Vsch\\TranslationManager\\ManagerServiceProvider\" --tag=public --force", "php artisan optimize" ], "post-root-package-install": [ "php -r \"copy('.env.example', '.env');\"" ], "post-create-project-cmd": [ "php artisan key:generate" ] } }
-
After updating composer, add the ServiceProviders to the providers array in config/app.php and comment out the original TranslationServiceProvider:
//Illuminate\Translation\TranslationServiceProvider::class, Vsch\UserPrivilegeMapper\UserPrivilegeMapperServiceProvider::class, Vsch\TranslationManager\ManagerServiceProvider::class, Vsch\TranslationManager\TranslationServiceProvider::class, Collective\Html\HtmlServiceProvider::class,
The TranslationServiceProvider is an extension to the standard functionality and is required in order for the web interface to work properly. It is backward compatible with the existing Translator since it is a subclass of it and only overrides implementation for new features.
-
add the Facade to the aliases array in config/app.php:
'Form' => Collective\Html\FormFacade::class, 'Html' => Collective\Html\HtmlFacade::class, 'UserCan' => Vsch\UserPrivilegeMapper\Facade\Privilege::class,
-
You need to publish then run the migrations for this package:
$ php artisan vendor:publish --provider="Vsch\TranslationManager\ManagerServiceProvider" --tag=migrations $ php artisan migrate
-
You need to publish the config file for this package. This will add the file
config/laravel-translation-manager.php
$ php artisan vendor:publish --provider="Vsch\TranslationManager\ManagerServiceProvider" --tag=config
-
You need to publish the web assets used by the translation manager web interface. This will add the assets to
public/vendor/laravel-translation-manager
$ php artisan vendor:publish --provider="Vsch\TranslationManager\ManagerServiceProvider" --tag=public
-
By default the web interface of the translation manager is available at
http://yourdomain.com/translations
. You can change this in the configuration file. The configuration file has 'web' and 'auth' middleware enabled on translator web interface routes, 'web' is required 'auth' is optional, you can add any other middleware to the route that you require. -
TranslationManager uses the vsch/user-privilege-mapper package that creates a mapping layer between your User model implementation and the need to test user privileges without knowing the implementation. You need to name privileges for the
UserPrivilegeMapper
via the Laravel macro mechanism. This should be done in the initialization files. A good place is the app/Providers/AppServiceProvider.php file, add the following to boot() function, if your User model has is_admin and is_editor attributes to identify users that have Admin and Editor privileges or justreturn true
in both cases if you don't have any way of determining user privileges:<?php \UserCan::macro("admin_translations", function () { return ($user = Auth::user()) && $user->is_admin; }); // return false to use the translator missing key lottery, true to always check missing keys for the user \UserCan::macro("bypass_translations_lottery", function () { return ($user = Auth::user()) && ($user->is_admin || $user->is_editor); }); ?>
In this example the User model implements two attributes: is_admin and is_editor. The admin user is allowed to manage translations: import, delete, export, etc., the editor user can only edit existing translations. However, both of these users will always log missing translation keys so that any missing translations will be visible to them instead of relying on the missing key lottery settings.
-
Yandex assisted translations requires setting the
yandex_translator_key
to your Yandex API key in theconfig/laravel-translation-manager.php
file, it is free to get and use. See: https://tech.yandex.com/translate/ -
If you want to override the Translation Manager web interface translations or add another locale you will need to publish the language files to your project by executing:
$ php artisan vendor:publish --provider="Vsch\TranslationManager\ManagerServiceProvider" --tag=lang
This will copy the translations to your project and allow you to view/edit them in the translation manager web interface.
-
If you want to customize views for the Translation Manager web interface you will need to publish the views to your project by executing:
$ php artisan vendor:publish --provider="Vsch\TranslationManager\ManagerServiceProvider" --tag=views
This will copy the views to your project under the
resources/views/vendor/laravel-translation-manager
directory. See: Modifying the default Views