最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

translation - Translate string inside twig template

programmeradmin1浏览0评论

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}}">
发布评论

评论列表(0)

  1. 暂无评论