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

osc2nuke's avatar

LoadTranslationsFrom (not a package)

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:

  • app/Modules/DummyTester

    • Admin
    • Database
    • Providers
    • resources
    • Module.php ( installer)
    • routes.php
  • Providers/DummyTesterServiceProvider.php:

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.

0 likes
1 reply
osc2nuke's avatar
osc2nuke
OP
Best Answer
Level 2

I found eventually the solution ( lol, i not expected that!). The last test worked, at the end it is obvious, but leaving it here for others:

            <button wire:click="edit" class="btn btn-primary mt-4">Default: {{ __('edit_test') }}</button>
            <button wire:click="edit" class="btn btn-primary mt-4">PHP: {{ __('edit_test', [], 'dummy-tester') }}</button>
            <button wire:click="edit" class="btn btn-primary mt-4">PHP namespace: {{ __('messages.edit_test', [], 'dummy-tester') }}</button>
            <button wire:click="edit" class="btn btn-primary mt-4">PHP idiot attempt: {{ __('dummy-tester::edit_test', [], 'messages') }}</button>
            <button wire:click="edit" class="btn btn-primary mt-4">PHP another idiot attemp: {{ __('messages::edit_test', [], 'dummy-tester') }}</button>
			<button wire:click="edit" class="btn btn-primary mt-4">PHP trans helper: {{ trans('dummy-tester::edit_test') }}</button>
//This last one did the trick
			<button wire:click="edit" class="btn btn-primary mt-4">PHP trans helper 2: {{ trans('dummy-tester::messages.edit_test') }}</button>

Please or to participate in this conversation.