translation - Translate string inside twig template

admin2025-03-20  4

I am trying to translate a string inside a placeholder in a twig (timber) template. But I cannot detect the string in WPML string translation.

<input type="text" id="s" name="s" value="" placeholder="{{ __('Search', 'textdomain') }}">

I am trying to translate a string inside a placeholder in a twig (timber) template. But I cannot detect the string in WPML string translation.

<input type="text" id="s" name="s" value="" placeholder="{{ __('Search', 'textdomain') }}">
Share Improve this question edited May 18, 2020 at 11:08 fuxia 107k38 gold badges255 silver badges459 bronze badges asked May 18, 2020 at 10:57 MMKMMK 5384 silver badges11 bronze badges 2
  • I'd guess WPML scans your code for potential translations and isn't picking this up then? Maybe try adding a reference to that translation somewhere in PHP code and see if that helps. And this is possibly a bug or enhancement report for WPML. – Rup Commented May 18, 2020 at 11:52
  • it is working fine with php code, just the strings inside twig template are not working – MMK Commented May 18, 2020 at 13:54
Add a comment  | 

1 Answer 1

Reset to default 1

I managed to assign a variable to context.

$context = Timber::get_context();
$context['search_placeholder'] = __("Suche","pixel_framework");

Timber::fetch('test.twig',$context);

inside twig

<input type="text" id="s" name="s" value="" placeholder=" {{search_placeholder}}">
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1742421008a212935.html

最新回复(0)