Log1x / acf-composer

Compose ACF Fields, Blocks, Widgets, and Option Pages with ACF Builder on Sage 10.
https://github.com/Log1x/acf-composer
MIT License
419 stars 57 forks source link

Localization issue for block name and description. #187

Closed gol4nsky closed 8 months ago

gol4nsky commented 9 months ago

Hi, Is there any solution with localization ? Using --construct and everything according to this https://roots.io/sage/docs/localization/#localization, the strings still appear in the originally encoded language and not translated.

Schwankenson commented 9 months ago

I think this is because

load_theme_textdomain('my_theme', get_template_directory() . '/resources/lang');

is called after the psr-4 class autoloader, which loads the block.

@Log1x - What is best practise for that? I have the same problem like @gol4nsky when I define fields like that:

public function fields()
{
    $bootstrapContainer = new FieldsBuilder('bootstrap_container');

    $bootstrapContainer
        ->addSelect(
            'width', 
            [
                'choices' => [
                    'default' => __('Default', 'my_theme'),
                    'full' => __('Full width', 'my_theme')
                ]
            ]

        )
        (...)

It works if I put load_theme_textdomain into the fields() function, but this is not really a good solution

Schwankenson commented 9 months ago

Update:

I put this code in functions.php of my sage theme:

/*
|--------------------------------------------------------------------------
| Load theme textdomain
|--------------------------------------------------------------------------
|
| Needs to be loaded before Auto Loader to have translations available in
| autoloader classes
|
*/  

load_theme_textdomain('mytheme', get_template_directory() . '/resources/lang');  

What do you think? Is this a good idea?