Overriding module translations
Created 3 years ago by keevitajaHello!
I can set new translation items from service provider or from route middleware. I just use Illuminate\Translation\Translator
and addLines
method. How ever i cannot override any module translations set in the language files. Here's a not working example:
<?php namespace Keevitaja\TestModule;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Translation\Translator;
class LoadTranslations
{
protected $trans;
public function __construct(Translator $trans)
{
$this->trans = $trans;
}
public function handle(Request $request, Closure $next)
{
$this->trans->addLines([
'message.logged_out' => 'testing'
], 'en', 'anomaly.module.users');
dd($this->trans->trans('anomaly.module.users::message.logged_out'));
return $next($request);
}
}
If i change the namespace to * i can get the message with trans('message.logged_out'). Is it possible to override module translations at all?
keevitaja
—
3 years ago
@ryanthompson sorry, i need to do this programmatically. how could i achieve it?
it is for my translations module: https://github.com/keevitaja/translations-module
ryanthompson
—
3 years ago
You would probably have to use the loader - I'd checkout how I do it - cause it merges not replaces namespaces. And adapt that to your needs.
Use the
addon:publish
command and modify the translation files directly thereafter.