Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

oriceon's avatar

Laravel lang from another path

Hello there. I want to create a multi site with multi languages support.

All`s good for now:

  1. i created folder structure:
/Agents/
    /Domains/
        /domain1.dev/
             /lang/
                 /en/
                     translations here...
             config.php
        /domain2.dev/
             /lang/
                 /en/
                     translations here...
             config.php
  1. I created a service provider where i load config from that paths, i load translator with namespace: $this->app['translator']->addNamespace('Agents', $domain_path . 'lang');

Now, the problem is that i want to remove /resources/lang/ entirely and move validation, pagination and passwords translations to my lang folders and need to find a way to load language by default from my custom place to escape using namespace in trans like trans('Agents::key ..') using directly trans('key').

With views i found a way to get views from custom place: $this->app['view']->addLocation($domain_path . 'lang/views/');

But with language i cannot find the right way.

0 likes
2 replies
oriceon's avatar
oriceon
OP
Best Answer
Level 8

I found a answer in other place, the solution:

  1. in \App\ i created DomainApplication.php
<?php namespace App;

class DomainApplication extends \Illuminate\Foundation\Application {
    public function langPath() {
        return '/path/to/new/lang/';
    }
}
  1. in /bootstrap/start.php i replaced $app new.. with
$app = new App\DomainApplication(
    realpath(__DIR__.'/../')
);

And now translations are loaded from new path and work without namespace:

dd(trans('passwords.password'));
3 likes
sicaboy's avatar

@oriceon If you use AI, it will tell you to do this, simpler:


class AppServiceProvider extends ServiceProvider
{
    public function boot(): void
    {   
        // Configure language path to use /lang directory instead of /resources/lang
        $this->app->useLangPath(base_path('lang'));
    }
}

Please or to participate in this conversation.