Overriding module translations
Created 3 years ago by keevitaja


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)
            'message.logged_out' => 'testing'
        ], 'en', 'anomaly.module.users');


        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?

ryanthompson  —  3 years ago

Use the addon:publish command and modify the translation files directly thereafter.

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.