<?php
namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Translation\Translator;
use App\Translation\CustomFileLoader;
use Illuminate\Filesystem\Filesystem;

class CustomTranslationServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->registerLoader();

        $this->app->singleton('translator', function ($app) {
            // $app['path.lang'] = public_path('lang');
            $loader = $app['translation.loader'];
            $locale = $app['config']['app.locale'];
            $trans = new Translator($loader, $locale);
            $trans->setFallback($app['config']['app.fallback_locale']);

            return $trans;
        });
    }

    protected function registerLoader()
    {
        $this->app->singleton('translation.loader', function ($app) {
            $adminUrl = config('amplivo.admin_url');
            return new CustomFileLoader(new Filesystem, $app['path.lang'], $adminUrl."lang");
        });
    }
}
