for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace RichanFongdasen\I18n;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Support\ServiceProvider as Provider;
class ServiceProvider extends Provider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
$this->publishAssets();
$this->registerMacro();
}
* Publish package assets.
protected function publishAssets()
$this->publishes([
realpath(__DIR__.'/../config/i18n.php') => config_path('i18n.php'),
], 'config');
realpath(__DIR__.'/../database/migrations/') => database_path('migrations'),
], 'migrations');
realpath(__DIR__.'/../storage/i18n/') => storage_path('i18n'),
], 'languages.json');
* Register the application services.
public function register()
$this->mergeConfigFrom(realpath(__DIR__.'/../config/i18n.php'), 'i18n');
$this->app->singleton(I18nService::class, function () {
return new I18nService(request());
});
* Register macro for Collection class.
protected function registerMacro()
Collection::macro('translate', function ($locale) {
$this->each(function ($item, $key) use ($locale) {
if (($item instanceof Model) && method_exists($item, 'translate')) {
$item->translate($locale);
return $key;