Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use database driver for Application Specific translations and use File Driver for Vendor Translations #251

Open
yob-yob opened this issue Sep 22, 2022 · 0 comments

Comments

@yob-yob
Copy link

yob-yob commented Sep 22, 2022

// at the moemnt, we're not supporting vendor specific translations

I was wondering also thou, since this package has it's own translations... but it does not include that in the database when syncing...

please tell me if I'm missing something here...

The reason why I was having trouble was because I'm using the package filament-admin... and this package is not finding the correct translations for the filament-admin package when using the database driver...

anyways... I've created a middleware to reset the translator when I'm on a specific path... for a quick fix of my problem...

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Translation\FileLoader;
use Illuminate\Translation\Translator;

class TranslationDriverManager
{
    protected $except = [
      'admin/*', 
      'telescope', 
      'horizon'
    ];

    public function handle(Request $request, Closure $next)
    {
      foreach ($this->except as $key => $value) {
        if ($request->is($value)) {
          app()->singleton('translation.loader', function ($app) {
              return new FileLoader($app['files'], $app['path.lang']);
          });

          app()->singleton('translator', function ($app) {
              $trans = new Translator($app['translation.loader'], $app['config']['app.locale']);
              $trans->setFallback($app['config']['app.fallback_locale']);
              return $trans;
          });
        }
      }

        return $next($request);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant