I noticed any string translations used for i18n localization are not working in the ./app directory. All other --include="app,config,resources,public/dist/js" inside the ./package.json are working and are written inside the ./resources/lang/radicle.pot.
Directory app
It seems the wp i18n make-pot can’t scan the ./app directory since none of the string translations like __(‘My example string‘, 'radicle'); are saved in the radicle.pot.
Usages in x-components
I also found the string translations won’t be saved to the radicle.pot when you pass a string translation as prop attribute to the Component.
// .resources/views/partials/content-none.blade.php
<x-no-results
:title="__('My title is not written inside the radicle.pot file.', 'radicle')"
:text="__('The content-none.blade.php gets scanned but these component constructor prop attributes are not inside the radicle.pot file.', 'radicle')"
/>
<p>{{ __('This a string translation I can translate.', 'radicle') }}</p>
I assume it’s because the Component runs inside the ./app directory at ./app/View/Components/NoResult.php.
<?php
namespace App\View\Components;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class NoResults extends Component
{
/**
* Create a new component instance.
*/
public function __construct(
public ?string $title = null,
public ?string $subtitle = null,
) {
//
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.no-results');
}
}
Even though the x-no-results is inside .resources/ the string translations won’t get recognized once they are inside the x-component prop. So the localization is not working in ./app & x-component props. Do you have any suggestions on how to resolve these issues?
Thank you for the response. I have tested your changes on the “translate:pot” but unfortunately without success. The translatable strings that are put directly into the x-component props are not showing up in the pot file.
@php(__('Success: I can translate this standalone string.', 'radicle'))
<x-alert type="warning" class="my-6" :message="__('Failed: I can\'t translate this string directly in a component prop!', 'radicle')">
{{ __('Success: I can translate this $slot.', 'radicle') }}
</x-alert>
I like to see we came up with the same workaround . For now we stick to this workaround. Is this something you will implement as fix later or is it currently not on your patch list?