zerospam / laravel-gettext

Adds localization support to laravel applications using PoEdit and GNU-Gettext.
99 stars 56 forks source link

[Question] multi domain configuration #12

Closed hanc2006 closed 6 years ago

hanc2006 commented 6 years ago

How should laravel-getext be configured to generate many domains (=different files) and then be able to use them all together inside the application without change domain every time?

LaravelGettext::setDomain($domain);

In a situation where I have many translations it becomes difficult to have only one file in poedit for translate.

  'source-paths' => [
        'booking' => ['../resources/views/www/booking'],
        'account' => ['../resources/views/www/account'],
        'casting' => ['../resources/views/www/casting'],
        'event' => ['../resources/views/www/event'],
        'profile' => ['../resources/views/www/profile'],
        'tutorial' => ['../resources/views/www/tutorial'],
        'registration' => ['../resources/views/www/registration'],
        'subscription' => ['../resources/views/www/subscription']
     ],
Belphemur commented 6 years ago

The cleanest solution I can think of is adding a new helper method where you could specify the domain like

_d($message, $domain, $args)

Which would take care of setting the domain for that exact string, then return to the previously set domain.

The other solution I see is to make LaravelGettext look for the string in all the domains, but this could lead to the wrong string found if they have the same key in different domains.

I would advise setting the domain directly in the Constructor of your controller, since usually you do different controllers for different business logic/domains.