2
votes

I'm using the Timber Library with Wordpress. Timber has the built in wordpress localization function {{__('my text', 'my-text-domain)}} The commit that supports these functions can be seen here:

https://github.com/timber/timber/pull/918/commits/9cd97a559b3a2ca4a348527c59472f5599155ef9

However, I was using the Loco translate plugin, but I realized that it does not parse Twig files so my template strings are not available for translation as I expected.

Is there another plugin I can use instead or any other suggestions?

I can manually translate the strings in Loco translate as Timber will pick them up with the functions.

But Loco doesn't scan for them automatically. No big deal but would be a nice feature.

1
In the end I created all the variables in php so they were picked up then I could still leave the functions in twig and they get picked up there too.weaveoftheride

1 Answers

1
votes

As of version 2.0.16-dev Loco Translate will extract PHP-style function calls from .twig files. i.e. a pattern like {{ __("foo","bar") }} will extract the string "foo" into the domain "bar".

To enable this you must add "twig" as a PHP extension in the plugin settings.

Prior to this version the same was achievable by prepending all .twig files with {#<?php#}. This hack is no longer required.

Disclosure: I am the author of the plugin.