Tested for hours, loosing it!
I'm working on a personal *two tables only CMS system.
I have a blanco Laravel with Livewire installed but now i'm stuck with loading languages from outside the resources directory.
The structure is pretty simple and straightforward:
<?php
namespace App\Modules\DummyTester\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Log;
class DummyTesterServiceProvider extends ServiceProvider
{
public function boot()
{
// Register routes with the 'web' middleware group
Route::middleware('web')->group(function () {
$this->loadRoutesFrom(base_path('app/Modules/DummyTester/routes.php'));
});
// Register views
$this->loadViewsFrom(base_path('app/Modules/DummyTester/resources/views'), 'dummy-tester');
// Register translations
$this->loadTranslationsFrom(base_path('app/Modules/DummyTester/resources/lang'), 'dummy-tester');
// Automatically register Livewire components from the Admin directory
$this->loadLivewireComponentsFrom(base_path('app/Modules/DummyTester/Admin'));
}
protected function loadLivewireComponentsFrom(string $directory)
{
if (!is_dir($directory)) {
return;
}
$namespace = 'App\\Modules\\DummyTester\\Admin';
$files = glob($directory . '/*.php');
foreach ($files as $file) {
$className = basename($file, '.php');
$fullClass = "{$namespace}\\{$className}";
if (!class_exists($fullClass)) {
continue;
}
$componentName = Str::kebab(str_replace('\\', '.', Str::after($fullClass, 'App\\')));
\Livewire\Livewire::component($componentName, $fullClass);
}
}
public function register()
{
//
}
}
LoadJsonTranslationsFrom (en.json) works as expected, but i wanted to use a namespace for the translations to prevent conflicts.
I performed my test with the messages.php sample given on the 12.x documentation page and have my translations as :
{{ __('messages.edit_test') }}
I also tried:
{{ trans('dummy-tester::edit_test') }}
PS: Keep in mind , i not use this a package, as the default doc's and simular Q&A are related to that.
Also the normal languages work.
If i move messages.php to the default resources/lang/en/ dir only this syntax works
{{ __('messages.edit_test') }}
I made sure there are no KEY conflicts in any other Eg; en.json or messages.php.