Custom polylang string translations

Hi everyone,

I’m fairly new to bricks and still learning…
Right now I’m trying to translate the header and footer templates using polylang.
As far as I’m aware, I have to make the template/design in one language, and then copy/translate the template and change stuff like titles, text and so on.
I would like to avoid copying the whole template only to change a few words.
Is it somehow possible to use translation strings in the fields?

I know I can manually register strings to polylang using pll_register_string (Function reference – Polylang), but how can I use it in “heading” or “rich text” elements for example?
Even better would be If I don’t have to register these strings manually.

I hope I describe my problem good enough and I’m looking forward to your feedback.
Thanks in advance,
friese

Nobody has an idea?
This makes using bricks kind of annoying and very inefficient in my opinion :frowning:

Help? :frowning:
Does really nobody has this problem?

Hey @friese,

you have to register the custom strings for translation. There is no way around it (that I know of). But then you can easily use them in your template (without duplicating and translating the actual template):

  1. Register the custom strings:
$custom_strings = [
    'bricks_header' => 'Das hier ist der Header',
    'bricks_footer' => 'Das hier ist der Footer',
];

foreach ( $custom_strings as $name => $string ) {
    pll_register_string( $name, $string );
}
  1. Translate the registered strings:

  1. Whitelist Polylang’s pll__ function to be used with the dynamic data echo tag:
add_filter( 'bricks/code/echo_function_names', function() {
    return [
        'pll__',
    ];
} );
  1. Use the pll__ function in your templates:

{echo:pll__('Das hier ist der Header')}

  1. Enjoy the result :wink::

Best,

André