1

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') }}">
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

1 Answer 1

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}}">
1
  • Interesting solution, because I think the issue is that the code in .twig files is not scanned by WPML, only in .php files. This seems sensible, potentially a locale file could even be created to store all of these and add them to context. e.g. en.php
    – csalmeida
    Commented Jun 16, 2023 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.